From de58e1e20c6f7ed11d0db779de18834b83ebeab6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 12:08:20 +0000 Subject: [PATCH 001/144] Auto-generated commit d9937088624c9707bf625ebb1bc84aae5af385fd --- index.d.ts | 64 ++ index.mjs | 4 + index.mjs.map | 1 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2758 insertions(+) create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..f3b446d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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: 2.0 + +/** +* Replace search occurrences with a replacement string. +* +* ## Notes +* +* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. +* +* @param str - input string +* @param search - search expression +* @param newval - replacement value or function +* @returns new string containing replacement(s) +* +* @example +* var str = 'beep'; +* var out = replace( str, 'e', 'o' ); +* // returns 'boop' +* +* @example +* var str = 'Hello World'; +* var out = replace( str, /world/i, 'Mr. President' ); +* // returns 'Hello Mr. President' +* +* @example +* var capitalize = require( `@stdlib/string/capitalize` ); +* +* var str = 'Oranges and lemons say the bells of St. Clement\'s'; +* +* function replacer( match, p1 ) { +* return capitalize( p1 ); +* } +* +* var out = replace( str, /([^\s]*)/gi, replacer); +* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' +*/ +declare function repeat( + str: string, + search: string | RegExp, + newval: string | Function +): string; + + +// EXPORTS // + +export = repeat; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..08b3dbf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var n=e,m=r,a=s.isPrimitive,d=t,o=i;var g=function(e,r,s){if(!a(e))throw new TypeError(o("invalid argument. First argument must be a string. Value: `%s`.",e));if(a(r))r=n(r),r=new RegExp(r,"g");else if(!d(r))throw new TypeError(o("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!a(s)&&!m(s))throw new TypeError(o("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",s));return e.replace(r,s)};export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..afafbfb --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/replace.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n"],"names":["rescape","require$$0","isFunction","require$$1","isString","require$$2","isPrimitive","isRegExp","require$$3","format","require$$4","lib","str","search","newval","TypeError","RegExp","replace"],"mappings":";;6aAsBA,IAAIA,EAAUC,EACVC,EAAaC,EACbC,EAAWC,EAAsCC,YACjDC,EAAWC,EACXC,EAASC,EA0Db,ICxCAC,EDoBA,SAAkBC,EAAKC,EAAQC,GAC9B,IAAMV,EAAUQ,GACf,MAAM,IAAIG,UAAWN,EAAQ,kEAAmEG,IAEjG,GAAKR,EAAUS,GACdA,EAASb,EAASa,GAClBA,EAAS,IAAIG,OAAQH,EAAQ,UAEzB,IAAMN,EAAUM,GACpB,MAAM,IAAIE,UAAWN,EAAQ,yFAA0FI,IAExH,IAAMT,EAAUU,KAAaZ,EAAYY,GACxC,MAAM,IAAIC,UAAWN,EAAQ,0FAA2FK,IAEzH,OAAOF,EAAIK,QAASJ,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4288e2f --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 89e2178898480df89457b88b826f65179e5fa895 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 31 May 2022 23:35:05 +0000 Subject: [PATCH 002/144] Auto-generated commit --- .editorconfig | 181 -------- .eslintrc.js | 1 - .gitattributes | 33 -- .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 --- .github/workflows/bundle.yml | 504 -------------------- .github/workflows/cancel.yml | 56 --- .github/workflows/close_pull_requests.yml | 44 -- .github/workflows/examples.yml | 62 --- .github/workflows/npm_downloads.yml | 108 ----- .github/workflows/productionize.yml | 160 ------- .github/workflows/publish.yml | 157 ------- .github/workflows/test.yml | 92 ---- .github/workflows/test_bundles.yml | 180 -------- .github/workflows/test_coverage.yml | 123 ----- .github/workflows/test_install.yml | 83 ---- .gitignore | 178 -------- .npmignore | 227 --------- .npmrc | 28 -- CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---------------------- README.md | 94 +--- benchmark/benchmark.js | 102 ----- bin/cli | 100 ---- branches.md | 53 --- docs/repl.txt | 42 -- docs/types/index.d.ts | 64 --- docs/types/test.ts | 60 --- docs/usage.txt | 9 - etc/cli_opts.json | 18 - examples/index.js | 40 -- index.mjs | 2 +- index.mjs.map | 2 +- lib/index.js | 45 -- lib/replace.js | 85 ---- package.json | 72 +-- stats.html | 2 +- test/fixtures/stdin_error.js.txt | 33 -- test/test.cli.js | 245 ---------- test/test.js | 161 ------- 42 files changed, 18 insertions(+), 4042 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/bundle.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts 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 delete mode 100644 lib/index.js delete mode 100644 lib/replace.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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +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 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 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/bundle.yml b/.github/workflows/bundle.yml deleted file mode 100644 index 10f472a..0000000 --- a/.github/workflows/bundle.yml +++ /dev/null @@ -1,504 +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: bundle - -# Workflow triggers: -on: - # Allow workflow to be manually run: - workflow_dispatch: - - # Run workflow upon completion of `productionize` workflow: - workflow_run: - workflows: ["productionize"] - types: [completed] - -# Workflow jobs: -jobs: - - # 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 - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # 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 - - # 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 branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, checkout branch and rebase on `main`: - - name: 'If `deno` exists, checkout branch and rebase on `main`' - if: steps.deno-branch-exists.outputs.remote-exists - continue-on-error: true - run: | - git checkout -b deno origin/deno - git rebase main -s recursive -X ours - while [ $? -ne 0 ]; do - git rebase --skip - done - - # If `deno` does not exist, checkout `main` and create `deno` branch: - - name: 'If `deno` does not exist, checkout `main` and create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout main - git checkout -b deno - - # 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 rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs 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: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno --force - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -201,7 +133,7 @@ beep ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9cf0385..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string-from-code-point' ); -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::regexp', function benchmark( b ) { - var out; - var str; - var re; - var i; - - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 52e6e5d..0000000 --- a/bin/cli +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1cdf90b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces `search` occurrences with a replacement `string`. - - When provided a `string` as the `search` value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f3b446d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replace search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( - str: string, - search: string | RegExp, - newval: string | Function -): string; - - -// EXPORTS // - -export = repeat; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 72c37fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The function does not compile if provided arguments of invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index fe5f20b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 454bcc6..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afd0647..0000000 --- a/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out; -var str; - -console.log( replace( 'beep', 'e', 'o' ) ); -// => 'boop' - -console.log( replace( 'Hello World', /world/i, 'Mr. President' ) ); -// => 'Hello Mr. President' - -str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} diff --git a/index.mjs b/index.mjs index 08b3dbf..1f6dcd8 100644 --- a/index.mjs +++ b/index.mjs @@ -1,4 +1,4 @@ // Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 /// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var n=e,m=r,a=s.isPrimitive,d=t,o=i;var g=function(e,r,s){if(!a(e))throw new TypeError(o("invalid argument. First argument must be a string. Value: `%s`.",e));if(a(r))r=n(r),r=new RegExp(r,"g");else if(!d(r))throw new TypeError(o("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!a(s)&&!m(s))throw new TypeError(o("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",s));return e.replace(r,s)};export{g as default}; +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";var n=s,m=e,o=r.isPrimitive,d=t,p=i;var h=function(s,e,r){if(!o(s))throw new TypeError(p("0hV3R",s));if(o(e))e=n(e),e=new RegExp(e,"g");else if(!d(e))throw new TypeError(p("0hVBB",e));if(!o(r)&&!m(r))throw new TypeError(p("0hVBC",r));return s.replace(e,r)};export{h as default}; //# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map index afafbfb..a744f2e 100644 --- a/index.mjs.map +++ b/index.mjs.map @@ -1 +1 @@ -{"version":3,"file":"index.mjs","sources":["../lib/replace.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n"],"names":["rescape","require$$0","isFunction","require$$1","isString","require$$2","isPrimitive","isRegExp","require$$3","format","require$$4","lib","str","search","newval","TypeError","RegExp","replace"],"mappings":";;6aAsBA,IAAIA,EAAUC,EACVC,EAAaC,EACbC,EAAWC,EAAsCC,YACjDC,EAAWC,EACXC,EAASC,EA0Db,ICxCAC,EDoBA,SAAkBC,EAAKC,EAAQC,GAC9B,IAAMV,EAAUQ,GACf,MAAM,IAAIG,UAAWN,EAAQ,kEAAmEG,IAEjG,GAAKR,EAAUS,GACdA,EAASb,EAASa,GAClBA,EAAS,IAAIG,OAAQH,EAAQ,UAEzB,IAAMN,EAAUM,GACpB,MAAM,IAAIE,UAAWN,EAAQ,yFAA0FI,IAExH,IAAMT,EAAUU,KAAaZ,EAAYY,GACxC,MAAM,IAAIC,UAAWN,EAAQ,0FAA2FK,IAEzH,OAAOF,EAAIK,QAASJ,EAAQC"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../lib/replace.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/error-tools-fmtprodmsg' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n"],"names":["rescape","require$$0","isFunction","require$$1","isString","require$$2","isPrimitive","isRegExp","require$$3","format","require$$4","lib","str","search","newval","TypeError","RegExp","replace"],"mappings":";;sbAsBA,IAAIA,EAAUC,EACVC,EAAaC,EACbC,EAAWC,EAAsCC,YACjDC,EAAWC,EACXC,EAASC,EA0Db,ICxCAC,EDoBA,SAAkBC,EAAKC,EAAQC,GAC9B,IAAMV,EAAUQ,GACf,MAAM,IAAIG,UAAWN,EAAQ,QAASG,IAEvC,GAAKR,EAAUS,GACdA,EAASb,EAASa,GAClBA,EAAS,IAAIG,OAAQH,EAAQ,UAEzB,IAAMN,EAAUM,GACpB,MAAM,IAAIE,UAAWN,EAAQ,QAASI,IAEvC,IAAMT,EAAUU,KAAaZ,EAAYY,GACxC,MAAM,IAAIC,UAAWN,EAAQ,QAASK,IAEvC,OAAOF,EAAIK,QAASJ,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 042680f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// MODULES // - -var replace = require( './replace.js' ); - - -// EXPORTS // - -module.exports = replace; diff --git a/lib/replace.js b/lib/replace.js deleted file mode 100644 index 8220166..0000000 --- a/lib/replace.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Replace search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - if ( isString( search ) ) { - search = rescape( search ); - search = new RegExp( search, 'g' ); - } - else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); - } - return str.replace( search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 513cfea..89104e2 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.10", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-format": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-from-code-point": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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 index 4288e2f..5c54e07 100644 --- a/stats.html +++ b/stats.html @@ -2669,7 +2669,7 @@ - - - - From 443f2c093991494fe78ec69f725a496f1452b8aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 05:05:22 +0000 Subject: [PATCH 005/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 94 +- benchmark/benchmark.js | 102 - bin/cli | 100 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 9 - etc/cli_opts.json | 18 - examples/index.js | 40 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/replace.js | 85 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 245 -- test/test.js | 161 -- 42 files changed, 2709 insertions(+), 3993 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/replace.js create mode 100644 stats.html 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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +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 what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1a0740a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T21:24:32.429Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +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 repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - 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 prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs 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 or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -201,7 +133,7 @@ beep ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9cf0385..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string-from-code-point' ); -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::regexp', function benchmark( b ) { - var out; - var str; - var re; - var i; - - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 52e6e5d..0000000 --- a/bin/cli +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1cdf90b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces `search` occurrences with a replacement `string`. - - When provided a `string` as the `search` value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 72c37fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The function does not compile if provided arguments of invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index fe5f20b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 454bcc6..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afd0647..0000000 --- a/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out; -var str; - -console.log( replace( 'beep', 'e', 'o' ) ); -// => 'boop' - -console.log( replace( 'Hello World', /world/i, 'Mr. President' ) ); -// => 'Hello Mr. President' - -str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} 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..70d28eb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18007ec --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;qcAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 042680f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// MODULES // - -var replace = require( './replace.js' ); - - -// EXPORTS // - -module.exports = replace; diff --git a/lib/replace.js b/lib/replace.js deleted file mode 100644 index 794e925..0000000 --- a/lib/replace.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Replace search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = rescape( search ); - search = new RegExp( search, 'g' ); - } - else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return str.replace( search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index d29a0d9..89104e2 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.10", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-from-code-point": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..0ca1000 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 7218c6f..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,245 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 090e1af..0000000 --- a/test/test.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string primitive', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'replaces all occurrences of letter `b`' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'replaces all occurrences of letter `b` by `cd`' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'replaces `Brute?`' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces found matches by values created from a replacer function', function test( t ) { - var expected; - var out; - var str; - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); -}); From c69b5df11890accf6702dc1ebeeca348a90edf14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 17:02:48 +0000 Subject: [PATCH 006/144] Transform error messages --- lib/replace.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/replace.js b/lib/replace.js index 8220166..794e925 100644 --- a/lib/replace.js +++ b/lib/replace.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -64,17 +64,17 @@ var format = require( '@stdlib/string-format' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = rescape( search ); search = new RegExp( search, 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return str.replace( search, newval ); } diff --git a/package.json b/package.json index 513cfea..d29a0d9 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@stdlib/process-read-stdin": "^0.0.x", "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From d044e2592bade1aa3c158f36b4da71d491568606 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 07:01:54 +0000 Subject: [PATCH 007/144] Remove files --- index.d.ts | 64 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2758 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 f3b446d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replace search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( - str: string, - search: string | RegExp, - newval: string | Function -): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 70d28eb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18007ec..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;qcAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0ca1000..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 81f33559db53b5d99edf136dc8dacadc37ece925 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 07:02:31 +0000 Subject: [PATCH 008/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 94 +- benchmark/benchmark.js | 102 - bin/cli | 100 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 9 - etc/cli_opts.json | 18 - examples/index.js | 40 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/replace.js | 85 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 245 -- test/test.js | 161 -- 42 files changed, 2709 insertions(+), 3993 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/replace.js create mode 100644 stats.html 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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +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 what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 21738ad..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T00:45:20.370Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +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 repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - 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 prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs 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 or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -201,7 +133,7 @@ beep ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9cf0385..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string-from-code-point' ); -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::regexp', function benchmark( b ) { - var out; - var str; - var re; - var i; - - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 52e6e5d..0000000 --- a/bin/cli +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1cdf90b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces `search` occurrences with a replacement `string`. - - When provided a `string` as the `search` value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 72c37fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The function does not compile if provided arguments of invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index fe5f20b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 454bcc6..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afd0647..0000000 --- a/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out; -var str; - -console.log( replace( 'beep', 'e', 'o' ) ); -// => 'boop' - -console.log( replace( 'Hello World', /world/i, 'Mr. President' ) ); -// => 'Hello Mr. President' - -str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} 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..70d28eb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18007ec --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;qcAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 042680f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// MODULES // - -var replace = require( './replace.js' ); - - -// EXPORTS // - -module.exports = replace; diff --git a/lib/replace.js b/lib/replace.js deleted file mode 100644 index 794e925..0000000 --- a/lib/replace.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Replace search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = rescape( search ); - search = new RegExp( search, 'g' ); - } - else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return str.replace( search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index d29a0d9..89104e2 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.10", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-from-code-point": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..68df48d --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 7218c6f..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,245 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 090e1af..0000000 --- a/test/test.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string primitive', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'replaces all occurrences of letter `b`' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'replaces all occurrences of letter `b` by `cd`' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'replaces `Brute?`' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces found matches by values created from a replacer function', function test( t ) { - var expected; - var out; - var str; - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); -}); From e41ab89ca1441b7554ba6823566238aff2bdcb84 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 4 Jul 2022 14:54:48 +0000 Subject: [PATCH 009/144] Transform error messages --- lib/replace.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/replace.js b/lib/replace.js index 8220166..794e925 100644 --- a/lib/replace.js +++ b/lib/replace.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -64,17 +64,17 @@ var format = require( '@stdlib/string-format' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = rescape( search ); search = new RegExp( search, 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return str.replace( search, newval ); } diff --git a/package.json b/package.json index 513cfea..d29a0d9 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@stdlib/process-read-stdin": "^0.0.x", "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 6a435ae4d95650e1aab764e675ccad3d2eeabdc4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 4 Jul 2022 15:27:07 +0000 Subject: [PATCH 010/144] Remove files --- index.d.ts | 64 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2758 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 f3b446d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replace search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( - str: string, - search: string | RegExp, - newval: string | Function -): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 70d28eb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18007ec..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;qcAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 68df48d..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d83c7e15c45156d56cf7969f1ef715ea6320d092 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 4 Jul 2022 15:27:45 +0000 Subject: [PATCH 011/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 94 +- benchmark/benchmark.js | 102 - bin/cli | 100 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 9 - etc/cli_opts.json | 18 - examples/index.js | 40 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/replace.js | 85 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 245 -- test/test.js | 161 -- 41 files changed, 2709 insertions(+), 3958 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/replace.js create mode 100644 stats.html 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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +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 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 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +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 repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - 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 prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -201,7 +133,7 @@ beep ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9cf0385..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string-from-code-point' ); -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::regexp', function benchmark( b ) { - var out; - var str; - var re; - var i; - - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 52e6e5d..0000000 --- a/bin/cli +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1cdf90b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces `search` occurrences with a replacement `string`. - - When provided a `string` as the `search` value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 72c37fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The function does not compile if provided arguments of invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index fe5f20b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 454bcc6..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afd0647..0000000 --- a/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out; -var str; - -console.log( replace( 'beep', 'e', 'o' ) ); -// => 'boop' - -console.log( replace( 'Hello World', /world/i, 'Mr. President' ) ); -// => 'Hello Mr. President' - -str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} 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..70d28eb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..18007ec --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;qcAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 042680f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// MODULES // - -var replace = require( './replace.js' ); - - -// EXPORTS // - -module.exports = replace; diff --git a/lib/replace.js b/lib/replace.js deleted file mode 100644 index 794e925..0000000 --- a/lib/replace.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Replace search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = rescape( search ); - search = new RegExp( search, 'g' ); - } - else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return str.replace( search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index d29a0d9..89104e2 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.10", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-from-code-point": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..0d06c1e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 7218c6f..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,245 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 090e1af..0000000 --- a/test/test.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string primitive', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'replaces all occurrences of letter `b`' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'replaces all occurrences of letter `b` by `cd`' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'replaces `Brute?`' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces found matches by values created from a replacer function', function test( t ) { - var expected; - var out; - var str; - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); -}); From 7f124a3fbc3b7fba2b072fc416094cb15bfe5870 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 12 Jul 2022 14:15:59 +0000 Subject: [PATCH 012/144] Transform error messages --- lib/replace.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/replace.js b/lib/replace.js index 8220166..794e925 100644 --- a/lib/replace.js +++ b/lib/replace.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -64,17 +64,17 @@ var format = require( '@stdlib/string-format' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = rescape( search ); search = new RegExp( search, 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return str.replace( search, newval ); } diff --git a/package.json b/package.json index d330041..5552898 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@stdlib/process-read-stdin": "^0.0.x", "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 4044a2c0e8d5cb129d9cb34650fb2097e77f83e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 12 Jul 2022 14:46:58 +0000 Subject: [PATCH 013/144] Remove files --- index.d.ts | 64 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2758 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 f3b446d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replace search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( - str: string, - search: string | RegExp, - newval: string | Function -): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 70d28eb..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 18007ec..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;qcAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0d06c1e..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From b9ef4a4b6cb43cee3abfe96a2b6b47ca863d86b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 12 Jul 2022 14:47:47 +0000 Subject: [PATCH 014/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/bundle_tags.yml | 125 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 691 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 94 +- benchmark/benchmark.js | 102 - bin/cli | 100 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 9 - etc/cli_opts.json | 18 - examples/index.js | 40 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/replace.js | 85 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 245 -- test/test.js | 161 -- 42 files changed, 2709 insertions(+), 4087 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/bundle_tags.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/replace.js create mode 100644 stats.html 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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +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 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 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/bundle_tags.yml b/.github/workflows/bundle_tags.yml deleted file mode 100644 index 46a96ae..0000000 --- a/.github/workflows/bundle_tags.yml +++ /dev/null @@ -1,125 +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: bundle_tags - -# Workflow triggers: -on: - # Run workflow when a new tag is pushed to the repository: - push: - tags: - - '*' - -# Workflow jobs: -jobs: - - # Define job to wait a minute before running the workflow... - waiting: - - # Define display name: - name: 'Waiting Period' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the steps to run: - steps: - - # Wait three minutes: - - name: 'Wait three minutes' - run: | - sleep 3m - - # Define job to publish bundle tags to GitHub... - create-tags: - - # Define display name: - name: 'Create bundle tags' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: waiting - - # Define the steps to run: - steps: - - # Wait for the productionize workflow to succeed: - - name: 'Wait for productionize workflow to succeed' - uses: lewagon/wait-on-check-action@v1.0.0 - timeout-minutes: 5 - with: - ref: main - check-regexp: 'Productionize' - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 60 - allowed-conclusions: success - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - git fetch --all - - # Create bundle tags: - - name: 'Create bundle tags' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - ESCAPED=$(echo $SLUG | sed -E 's/\//\\\//g') - - git checkout -b deno origin/deno - sed -i -E "s/$ESCAPED@deno/$ESCAPED@$VERSION-deno/g" README.md - git add README.md - git commit -m "Update README.md for Deno bundle $VERSION" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - sed -i -E "s/$ESCAPED@$VERSION-deno/$ESCAPED@deno/g" README.md - git add README.md - git commit -m "Revert changes to README.md for Deno bundle $VERSION" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - git checkout -b umd origin/umd - sed -i -E "s/$ESCAPED@umd/$ESCAPED@$VERSION-umd/g" README.md - git add README.md - git commit -m "Update README.md for UMD bundle $VERSION" - git tag -a $VERSION-umd -m "$VERSION-umd" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-umd - sed -i -E "s/$ESCAPED@$VERSION-umd/$ESCAPED@umd/g" README.md - git add README.md - git commit -m "Revert changes to README.md for UMD bundle $VERSION" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" umd - - git checkout -b esm origin/esm - sed -i -E "s/$ESCAPED@esm/$ESCAPED@$VERSION-esm/g" README.md - git add README.md - git commit -m "Update README.md for ESM bundle $VERSION" - git tag -a $VERSION-esm -m "$VERSION-esm" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-esm - sed -i -E "s/$ESCAPED@$VERSION-esm/$ESCAPED@esm/g" README.md - git add README.md - git commit -m "Revert changes to README.md for ESM bundle $VERSION" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" esm diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 0a144b2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,691 +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: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - 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 prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -201,7 +133,7 @@ beep ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9cf0385..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string-from-code-point' ); -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::regexp', function benchmark( b ) { - var out; - var str; - var re; - var i; - - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 52e6e5d..0000000 --- a/bin/cli +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1cdf90b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces `search` occurrences with a replacement `string`. - - When provided a `string` as the `search` value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 72c37fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The function does not compile if provided arguments of invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index fe5f20b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 454bcc6..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afd0647..0000000 --- a/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out; -var str; - -console.log( replace( 'beep', 'e', 'o' ) ); -// => 'boop' - -console.log( replace( 'Hello World', /world/i, 'Mr. President' ) ); -// => 'Hello Mr. President' - -str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} 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..c752848 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..07619dd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;4cAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 042680f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// MODULES // - -var replace = require( './replace.js' ); - - -// EXPORTS // - -module.exports = replace; diff --git a/lib/replace.js b/lib/replace.js deleted file mode 100644 index 794e925..0000000 --- a/lib/replace.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Replace search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = rescape( search ); - search = new RegExp( search, 'g' ); - } - else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return str.replace( search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5552898..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-from-code-point": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..95e76e2 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 7218c6f..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,245 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 090e1af..0000000 --- a/test/test.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string primitive', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'replaces all occurrences of letter `b`' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'replaces all occurrences of letter `b` by `cd`' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'replaces `Brute?`' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces found matches by values created from a replacer function', function test( t ) { - var expected; - var out; - var str; - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); -}); From 930edf82d0b02213c353adeac687933c27605054 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 04:41:55 +0000 Subject: [PATCH 015/144] Transform error messages --- lib/replace.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/replace.js b/lib/replace.js index 8220166..794e925 100644 --- a/lib/replace.js +++ b/lib/replace.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -64,17 +64,17 @@ var format = require( '@stdlib/string-format' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = rescape( search ); search = new RegExp( search, 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return str.replace( search, newval ); } diff --git a/package.json b/package.json index d330041..5552898 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@stdlib/process-read-stdin": "^0.0.x", "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 0888278cf3944966a6c2801dfdff4df38572d982 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 19:45:52 +0000 Subject: [PATCH 016/144] Remove files --- index.d.ts | 64 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2758 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 f3b446d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replace search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( - str: string, - search: string | RegExp, - newval: string | Function -): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c752848..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 07619dd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;4cAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 95e76e2..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 3f0dfa958c0efef15c73c173d75250651b120dee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 19:46:57 +0000 Subject: [PATCH 017/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 94 +- benchmark/benchmark.js | 102 - bin/cli | 100 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 9 - etc/cli_opts.json | 18 - examples/index.js | 40 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/replace.js | 85 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 245 -- test/test.js | 161 -- 42 files changed, 2709 insertions(+), 4032 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/replace.js create mode 100644 stats.html 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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +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 what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cfdc6c7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T00:48:41.057Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +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: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -201,7 +133,7 @@ beep ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9cf0385..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string-from-code-point' ); -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::regexp', function benchmark( b ) { - var out; - var str; - var re; - var i; - - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, fromCodePoint( i%126 ) ); - if ( !isString( out ) ) { - 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 52e6e5d..0000000 --- a/bin/cli +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // Check if we are receiving data from `stdin`... - if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1cdf90b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces `search` occurrences with a replacement `string`. - - When provided a `string` as the `search` value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 72c37fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The function does not compile if provided arguments of invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index fe5f20b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 454bcc6..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afd0647..0000000 --- a/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out; -var str; - -console.log( replace( 'beep', 'e', 'o' ) ); -// => 'boop' - -console.log( replace( 'Hello World', /world/i, 'Mr. President' ) ); -// => 'Hello Mr. President' - -str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} 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..ed15922 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4d6b149 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;mdAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 042680f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// MODULES // - -var replace = require( './replace.js' ); - - -// EXPORTS // - -module.exports = replace; diff --git a/lib/replace.js b/lib/replace.js deleted file mode 100644 index 794e925..0000000 --- a/lib/replace.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Replace search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = rescape( search ); - search = new RegExp( search, 'g' ); - } - else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return str.replace( search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5552898..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-from-code-point": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..1e9bc72 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 7218c6f..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,245 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 090e1af..0000000 --- a/test/test.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string primitive', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'replaces all occurrences of letter `b`' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'replaces all occurrences of letter `b` by `cd`' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'replaces `Brute?`' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces found matches by values created from a replacer function', function test( t ) { - var expected; - var out; - var str; - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); -}); From 683d0379dd495b97f9d6520acbbff59bbdccc44d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 23 Sep 2022 16:09:04 +0000 Subject: [PATCH 018/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index b5179a3..6c3aa4f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From fe9f960ecc1a4a26826a40015b014f00321258d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 23 Sep 2022 16:13:02 +0000 Subject: [PATCH 019/144] Remove files --- index.d.ts | 64 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2758 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 f3b446d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replace search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( - str: string, - search: string | RegExp, - newval: string | Function -): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ed15922..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function n(n,o,d){if(!r(n))throw new TypeError(i("0hV3R",n));if(r(o))o=s(o),o=new RegExp(o,"g");else if(!t(o))throw new TypeError(i("0hVBB",o));if(!r(d)&&!e(d))throw new TypeError(i("0hVBC",d));return n.replace(o,d)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4d6b149..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/replace.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","rescape","RegExp","isRegExp","isFunction"],"mappings":";;mdAgEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAASK,EAASL,GAClBA,EAAS,IAAIM,OAAQN,EAAQ,UAEzB,IAAMO,EAAUP,GACpB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOF,EAAID,QAASE,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e9bc72..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1029a7ebcd57b9dd5c4542934451b0b1247af7e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 23 Sep 2022 16:13:50 +0000 Subject: [PATCH 020/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 125 +- benchmark/benchmark.js | 197 -- bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 --- test/test.js | 165 -- 41 files changed, 2709 insertions(+), 4238 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +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: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4997b83 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..14ae532 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 6c3aa4f..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..4ccfebb --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From b9b5db868a4914bbfdc61848943bd72686d370e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:45:49 +0000 Subject: [PATCH 021/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index b5179a3..6c3aa4f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 6d863821b537e3a695248a875d83695294e62b2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 19:39:37 +0000 Subject: [PATCH 022/144] Remove files --- index.d.ts | 60 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2754 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4997b83..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 14ae532..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4ccfebb..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 866285c70c8d3fbe74ae4ad0817efb0d2b59e53e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 19:40:22 +0000 Subject: [PATCH 023/144] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 125 +- benchmark/benchmark.js | 197 -- bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 --- test/test.js | 165 -- 42 files changed, 2709 insertions(+), 4239 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c2af747..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:08:48.383Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) 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 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - 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 "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - 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 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +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: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - 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 - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # 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 + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4997b83 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..14ae532 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 6c3aa4f..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..f22f9da --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 55af2ad5f246bc5a48dfb5ada2ab0462b662988f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 02:32:55 +0000 Subject: [PATCH 024/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index b5179a3..6c3aa4f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From cd388bb3aab6822f6e8a5123e6e05da8085fee0a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 15:50:26 +0000 Subject: [PATCH 025/144] Remove files --- index.d.ts | 60 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2754 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4997b83..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 14ae532..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f22f9da..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a5eb5eb732cc715e41d695121770a0a53df29e16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 15:51:08 +0000 Subject: [PATCH 026/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 125 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 42 files changed, 4064 insertions(+), 4239 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8e7e3c7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T00:55:19.691Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +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: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4997b83 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e67b491 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 6c3aa4f..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..45084ad --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 56615cec05b7cafdb75cf880d0b7ec4a8ddd3a62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 23:36:18 +0000 Subject: [PATCH 027/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index b5179a3..6c3aa4f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 16f00c6d4e3433f2f6133a0598df6e058c06a5ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:38:20 +0000 Subject: [PATCH 028/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4109 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4997b83..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e67b491..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 45084ad..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4ded86c854a0e80a9cf10b151a6f8e125204ae54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:38:55 +0000 Subject: [PATCH 029/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 125 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 42 files changed, 4064 insertions(+), 4260 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b11c96d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T21:05:31.812Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +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: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4997b83 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e67b491 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 6c3aa4f..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "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..944fe6c --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From ededa860f421792655d36f8bc01d721df49f1764 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 03:20:24 +0000 Subject: [PATCH 030/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 3f4443d..20d8481 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From e0d164d9b9c85260b478996172e97b6bf967074c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:27:22 +0000 Subject: [PATCH 031/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4109 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4997b83..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e67b491..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isRegExp from '@stdlib/assert-is-regexp' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport base from '@stdlib/string-base-replace' ;\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize' ;\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 944fe6c..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 111df3466ba3bc86d4da1b15dae60c54a23977ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:27:56 +0000 Subject: [PATCH 032/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 125 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 42 files changed, 4064 insertions(+), 4265 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b2b7c13..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T00:56:09.088Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +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: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; 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' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4997b83 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 20d8481..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "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..3caeef9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 055b6c4a7f83521422b507bac641e01c98cba1a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 00:45:03 +0000 Subject: [PATCH 033/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index df7032f..63dd7b0 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 4f65724fbbf5fe2fb3036f6806ea7e63d286fc61 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 11:54:31 +0000 Subject: [PATCH 034/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4109 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4997b83..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3caeef9..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 0e0707d238494a635640829e314c927b68f9aa9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 11:55:09 +0000 Subject: [PATCH 035/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 125 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 42 files changed, 4064 insertions(+), 4276 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9267c82..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T00:44:28.991Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +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 - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 63dd7b0..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "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" - }, - "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..0b5a8dc --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 29d36f7fb360ecf45118764661de3f38d423eb70 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:35:03 +0000 Subject: [PATCH 036/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index df7032f..63dd7b0 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.x", "@stdlib/streams-node-stdin": "^0.0.x", "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-escape-regexp-string": "^0.0.x", "@stdlib/utils-regexp-from-string": "^0.0.x" }, From 137faeba43e68dc38db4bac4c89d83f2ac38f6aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 11:35:36 +0000 Subject: [PATCH 037/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4109 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0b5a8dc..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 81ba90c03b28bf96f27603f037fd7d7d8e590e1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 11:36:16 +0000 Subject: [PATCH 038/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 125 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 53 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 42 files changed, 6197 insertions(+), 4276 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 03e48be..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T00:53:07.506Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +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 - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -228,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7b49109..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace" -click B href "https://github.com/stdlib-js/string-replace/tree/main" -click C href "https://github.com/stdlib-js/string-replace/tree/production" -click D href "https://github.com/stdlib-js/string-replace/tree/esm" -click E href "https://github.com/stdlib-js/string-replace/tree/deno" -click F href "https://github.com/stdlib-js/string-replace/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 63dd7b0..10781ab 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-regexp": "^0.0.x", - "@stdlib/assert-is-regexp-string": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/cli-ctor": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/process-read-stdin": "^0.0.x", - "@stdlib/regexp-eol": "^0.0.x", - "@stdlib/streams-node-stdin": "^0.0.x", - "@stdlib/string-base-replace": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-escape-regexp-string": "^0.0.x", - "@stdlib/utils-regexp-from-string": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.x", - "@stdlib/assert-is-windows": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/process-exec-path": "^0.0.x", - "@stdlib/string-capitalize": "^0.0.x", - "@stdlib/string-replace": "^0.0.x", - "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" - }, - "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..ad35922 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From ad6a5cf37fd8348d71a8894c79274567dc185af0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 02:06:58 +0000 Subject: [PATCH 039/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From 7e95f9a1afa4ea057d38cc4c1f85cebfeab40668 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:13:13 +0000 Subject: [PATCH 040/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ad35922..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6ad568c8dc0e9cea3546c34e82f01778611bdbf0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:13:56 +0000 Subject: [PATCH 041/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 1007 ---- .github/workflows/publish.yml | 236 - .github/workflows/publish_cli.yml | 159 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 43 files changed, 6197 insertions(+), 4784 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4884ca9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T01:26:21.554Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 240c5f2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1007 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/tree/cli \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..255cf97 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 3c6cd59375127cdeeffa08aa19d9de7f9911deca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 02:10:27 +0000 Subject: [PATCH 042/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From 05e7ef4761da17bafcdb69aa6792cf08816277b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 04:59:43 +0000 Subject: [PATCH 043/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 255cf97..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 75ec90823ae05c896c5184ebbba7175f18478b34 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 05:00:24 +0000 Subject: [PATCH 044/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 1007 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 43 files changed, 6197 insertions(+), 4796 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index afeb1b6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T01:30:45.994Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 240c5f2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1007 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/tree/cli \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..b12d24b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 9620ac6cee7c97501f1736e0543554adebefda2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 02:07:01 +0000 Subject: [PATCH 045/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From 26ace6120905e67eed181b190be2ea4e744aa6c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 04:50:28 +0000 Subject: [PATCH 046/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b12d24b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 20657fb6cb8a9f42ba1cf05c5dad91580defc14b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 04:51:24 +0000 Subject: [PATCH 047/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 1007 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 43 files changed, 6197 insertions(+), 4796 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0dd9241..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T01:28:13.202Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 240c5f2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1007 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/tree/cli \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..e3d8d70 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 2cdf3d1f7f875f309c0612a2bc037c6f7e6fbc98 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 02:08:17 +0000 Subject: [PATCH 048/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From 35641685cc2020522e93bd890ca1d727ac333583 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:00:04 +0000 Subject: [PATCH 049/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e3d8d70..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2ed19a36768fbd44a9bb53b579abe3d99ee3d3ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:00:49 +0000 Subject: [PATCH 050/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 1007 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 43 files changed, 6197 insertions(+), 4796 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e8dca3d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T01:29:28.667Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 240c5f2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1007 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/tree/cli \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..a1607a9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 79b91ca91c6d6e7249289a2479fbb3e8083cd588 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 02:09:09 +0000 Subject: [PATCH 051/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From 5f30d184a9c4e69b293e0cda1d6391fc19817bb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:07:04 +0000 Subject: [PATCH 052/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a1607a9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7178ead853a0ea1362fc7cec3a3b44c0069da050 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:07:37 +0000 Subject: [PATCH 053/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 1007 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 43 files changed, 6197 insertions(+), 4796 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 709d508..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T01:29:43.981Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 240c5f2..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1007 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/tree/cli \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..d174db1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 9c05a9a..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 82d8d9b87c194f50727d1d7a8b9c1f796b26944e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:13:50 +0000 Subject: [PATCH 054/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9c66c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '0hV3R', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '0hVBB', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '0hVBC', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From b34995814a693f4c68950336a169b0bc0aafcef1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:22:58 +0000 Subject: [PATCH 055/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d174db1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cb7babb111958ce18ad35b4d8d99d5c67f083338 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:23:33 +0000 Subject: [PATCH 056/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 1007 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 43 files changed, 6197 insertions(+), 4796 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100755 bin/cli delete mode 100644 branches.md 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4a4aca1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T01:31:33.014Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 952a131..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1007 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/tree/cli \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4f2e111 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a446329 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9c66c95..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '0hV3R', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '0hVBB', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '0hVBC', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..eb062e5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 5d9f8d3cce5597b16d43c5d2e3ee4e4a4e8f8c0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 00:48:57 +0000 Subject: [PATCH 057/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..a50b3a2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F,Ex', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT,M4', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU,M5', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index e498124..e5fa928 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.0.7", "@stdlib/streams-node-stdin": "^0.0.7", "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-escape-regexp-string": "^0.0.9", "@stdlib/utils-regexp-from-string": "^0.0.9" }, From 79489da22dd4cb67ad22c6eaafde8194aaa0fbef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:05:37 +0000 Subject: [PATCH 058/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c117b35..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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: 2.0 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4f2e111..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("0hV3R",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("0hVBB",m));if(!t(o)&&!e(o))throw new TypeError(i("0hVBC",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a446329..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '0hV3R', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '0hVBB', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '0hVBC', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb062e5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3a7d37f5888572d2861cafe664dc8fbd325a6b4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:06:24 +0000 Subject: [PATCH 059/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 992 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 45 files changed, 6197 insertions(+), 4795 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 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile 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/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 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index b61e587..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,992 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -229,7 +129,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..f520716 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d21a605 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index e5fa928..2af7e76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.0.11", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-regexp": "^0.0.7", - "@stdlib/assert-is-regexp-string": "^0.0.9", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/cli-ctor": "^0.0.3", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/process-read-stdin": "^0.0.7", - "@stdlib/regexp-eol": "^0.0.7", - "@stdlib/streams-node-stdin": "^0.0.7", - "@stdlib/string-base-replace": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-escape-regexp-string": "^0.0.9", - "@stdlib/utils-regexp-from-string": "^0.0.9" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.0.8", - "@stdlib/assert-is-windows": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/process-exec-path": "^0.0.7", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..5e84d10 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 7e33aa7314c1ee54ae82c0a62cce731dd6874be7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:45:54 +0000 Subject: [PATCH 060/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..a50b3a2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F,Ex', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT,M4', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU,M5', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 2c02e38..857bfde 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.0", "@stdlib/streams-node-stdin": "^0.1.0", "@stdlib/string-base-replace": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/utils-escape-regexp-string": "^0.1.0", "@stdlib/utils-regexp-from-string": "^0.1.0" }, From 26882485e7d119ee9206b62afb39c3ac3f73d698 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:53:24 +0000 Subject: [PATCH 061/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 001dbee..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f520716..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.0.9-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.0.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d21a605..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;ijBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5e84d10..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 332dd471e9819644efcb0e29158c68f1584ed0f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:54:01 +0000 Subject: [PATCH 062/144] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 992 ---- .github/workflows/publish.yml | 242 - .github/workflows/publish_cli.yml | 165 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 46 files changed, 6197 insertions(+), 4830 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 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/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 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 297dd73..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 1d74b0e..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index b61e587..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,992 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..ba8fdf2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.0-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c54c072 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 857bfde..666fd76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-regexp": "^0.1.0", - "@stdlib/assert-is-regexp-string": "^0.1.0", - "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/cli-ctor": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.0", - "@stdlib/process-read-stdin": "^0.1.0", - "@stdlib/regexp-eol": "^0.1.0", - "@stdlib/streams-node-stdin": "^0.1.0", - "@stdlib/string-base-replace": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/utils-escape-regexp-string": "^0.1.0", - "@stdlib/utils-regexp-from-string": "^0.1.0" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.0", - "@stdlib/assert-is-windows": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/process-exec-path": "^0.1.0", - "@stdlib/string-capitalize": "^0.0.9", - "@stdlib/string-replace": "^0.0.11", - "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" - }, - "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..c1ec9ae --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 82ede607ace02490279bf27451e2ceede4efc83c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:58:47 +0000 Subject: [PATCH 063/144] 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 e8120a6..b1d2960 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@esm/index.mjs'; +import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@v0.1.0-esm/index.mjs'; ``` #### replace( str, search, newval ) @@ -97,7 +97,7 @@ var out = replace( str, /([^\s]+)/gi, replacer ); - - - - From f96ee6c6e33a6c35c3037be918453aaea1f25be4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 20:21:36 +0000 Subject: [PATCH 067/144] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1009 ---- .github/workflows/publish.yml | 247 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 165 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 48 files changed, 6197 insertions(+), 5062 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 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 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5876d48..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T01:16:26.300Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ff5cb69..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 2eecd49..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1009 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..ba8fdf2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.0-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c54c072 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 0009735..666fd76 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.0", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-regexp": "^0.1.0", - "@stdlib/assert-is-regexp-string": "^0.1.0", - "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/cli-ctor": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.0", - "@stdlib/process-read-stdin": "^0.1.0", - "@stdlib/regexp-eol": "^0.1.0", - "@stdlib/streams-node-stdin": "^0.1.0", - "@stdlib/string-base-replace": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/utils-escape-regexp-string": "^0.1.0", - "@stdlib/utils-regexp-from-string": "^0.1.0" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.0", - "@stdlib/assert-is-windows": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/process-exec-path": "^0.1.0", - "@stdlib/string-capitalize": "^0.1.0", - "@stdlib/string-replace": "^0.1.0", - "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" - }, - "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..7130b1d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index d6247ac..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 28d5d70c6ac5f37e4e9da76e3efe249b5f61ef8b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 02:00:19 +0000 Subject: [PATCH 068/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..a50b3a2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F,Ex', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT,M4', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU,M5', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index fded732..cacee17 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.1", "@stdlib/streams-node-stdin": "^0.1.1", "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-escape-regexp-string": "^0.1.1", "@stdlib/utils-regexp-from-string": "^0.1.1" }, From 176d4e2c69898ef777cf41eaa7c5d774fc85997a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 10:53:07 +0000 Subject: [PATCH 069/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 001dbee..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba8fdf2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.0-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c54c072..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7130b1d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 60a48dfb58e0e861536e63cdb02cee04aff7d6cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 10:53:49 +0000 Subject: [PATCH 070/144] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1009 ---- .github/workflows/publish.yml | 247 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 165 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 47 files changed, 6197 insertions(+), 5061 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 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 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ff5cb69..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 2eecd49..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1009 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..e080708 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c54c072 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index cacee17..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.0", - "@stdlib/assert-is-windows": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/process-exec-path": "^0.1.0", - "@stdlib/string-capitalize": "^0.1.0", - "@stdlib/string-replace": "^0.1.0", - "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" - }, - "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..1e6f133 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index d6247ac..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 6addea0cf44b6356e00bf256a94189f878a0751d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 15:40:17 +0000 Subject: [PATCH 071/144] 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 67e1d69..327a16e 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@esm/index.mjs'; +import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@v0.1.1-esm/index.mjs'; ``` #### replace( str, search, newval ) @@ -97,7 +97,7 @@ var out = replace( str, /([^\s]+)/gi, replacer ); - - - - From 84458dd0de6cb2459842767c571dc11a4d63ce40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 21:53:42 +0000 Subject: [PATCH 075/144] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1009 ---- .github/workflows/publish.yml | 247 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 165 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 47 files changed, 6197 insertions(+), 5061 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 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 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ff5cb69..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 2eecd49..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1009 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..94ace38 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c54c072 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index be9c6f7..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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" - }, - "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..06346f6 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index d6247ac..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 0807cbb29a1e38db09f7b9091caa2a8b1584d96e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 18 Oct 2023 03:56:56 +0000 Subject: [PATCH 076/144] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a01f351..be9c6f7 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.1", "@stdlib/streams-node-stdin": "^0.1.1", "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-escape-regexp-string": "^0.1.1", "@stdlib/utils-regexp-from-string": "^0.1.1" }, From 6c89d01061ae86d00949d718918e756e5f6c3d71 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 18 Oct 2023 04:18:51 +0000 Subject: [PATCH 077/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 001dbee..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 94ace38..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c54c072..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 06346f6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2434b838fb1ceaf0e070da3f4cd857a48e81edca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 18 Oct 2023 04:19:30 +0000 Subject: [PATCH 078/144] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1009 ---- .github/workflows/publish.yml | 255 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 47 files changed, 6197 insertions(+), 4937 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 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 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ff5cb69..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 2eecd49..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1009 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..532fd0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..976683d --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 5db827e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index be9c6f7..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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" - }, - "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..7d01f25 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 0702ff963a6d8e885b15831a18c7ca28acab444e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 02:30:25 +0000 Subject: [PATCH 079/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..a50b3a2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F,Ex', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT,M4', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU,M5', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index a01f351..be9c6f7 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.1", "@stdlib/streams-node-stdin": "^0.1.1", "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-escape-regexp-string": "^0.1.1", "@stdlib/utils-regexp-from-string": "^0.1.1" }, From 01d293a873edef5284ee961738630cb3e15d918f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 19:59:42 +0000 Subject: [PATCH 080/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 001dbee..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 532fd0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 976683d..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7d01f25..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 543faea1c7c6849178e634503cc3c130ceffe12e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 20:00:18 +0000 Subject: [PATCH 081/144] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1009 ---- .github/workflows/publish.yml | 255 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 48 files changed, 6197 insertions(+), 4938 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 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 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f3eb4eb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T01:17:10.074Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ff5cb69..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 2eecd49..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1009 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..94ace38 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c54c072 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index be9c6f7..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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" - }, - "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..e24bd15 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 5d08358737b1bb5ee6e42b6b3f97f8e118ca824d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 02:25:44 +0000 Subject: [PATCH 082/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..a50b3a2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F,Ex', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT,M4', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU,M5', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 6bfd439..a6af95a 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.1", "@stdlib/streams-node-stdin": "^0.1.1", "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-escape-regexp-string": "^0.1.1", "@stdlib/utils-regexp-from-string": "^0.1.1" }, From 676d78021848a6faaad52716a61db2ff11e9bc05 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:47:52 +0000 Subject: [PATCH 083/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 001dbee..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 94ace38..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c54c072..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e24bd15..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8fc06fb44311c48479d9bbd6253bd9c904ad9901 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:48:32 +0000 Subject: [PATCH 084/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1011 ---- .github/workflows/publish.yml | 255 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 48 files changed, 6197 insertions(+), 4935 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 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 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/.keepalive b/.github/.keepalive deleted file mode 100644 index 92e61d5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T01:21:31.495Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index ff5cb69..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6957ebf..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1011 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 11e2b27..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..94ace38 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c54c072 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 a50b3a2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F,Ex', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT,M4', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU,M5', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index a6af95a..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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" - }, - "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..d62cb48 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 2da206be2075ad75d2394d4d677481ff621d0219 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 01:58:04 +0000 Subject: [PATCH 085/144] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 46ba450..f91e35c 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.1", "@stdlib/streams-node-stdin": "^0.1.1", "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-escape-regexp-string": "^0.1.1", "@stdlib/utils-regexp-from-string": "^0.1.1" }, From fedfa7f271f1629d3dab7ec3ec3c32d6c4887c65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:13:37 +0000 Subject: [PATCH 086/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c3baab8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 94ace38..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F,Ex",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT,M4",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU,M5",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c54c072..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F,Ex', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT,M4', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU,M5', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d62cb48..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 98720a2b2327f3235dd217d30b180be04ff03b11 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:13:55 +0000 Subject: [PATCH 087/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1011 ---- .github/workflows/publish.yml | 255 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 126 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 57 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 49 files changed, 6197 insertions(+), 4941 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/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/.keepalive b/.github/.keepalive deleted file mode 100644 index d2ba75a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T01:15:20.755Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index abe8730..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 96d504a..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1011 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -240,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index ded9fae..0000000 --- a/branches.md +++ /dev/null @@ -1,57 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. -- **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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..d88a3c3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..976683d --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 5db827e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index f91e35c..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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.1.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..3379fc1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 62c8992b3b4452624b6b4333a05068ba556b42e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 01:59:39 +0000 Subject: [PATCH 088/144] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 46ba450..f91e35c 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.1.1", "@stdlib/streams-node-stdin": "^0.1.1", "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-escape-regexp-string": "^0.1.1", "@stdlib/utils-regexp-from-string": "^0.1.1" }, From fa8799a1629911a3f151a4013d22413be1e5c45a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:20:51 +0000 Subject: [PATCH 089/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 c3baab8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( `@stdlib/string/capitalize` ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d88a3c3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 976683d..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3379fc1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 95fbd75ff0da2361796d59e9a188b29ef356ab62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:21:08 +0000 Subject: [PATCH 090/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 1012 ---- .github/workflows/publish.yml | 255 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 49 files changed, 6197 insertions(+), 4947 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/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/.keepalive b/.github/.keepalive deleted file mode 100644 index 0bc56e7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T01:22:07.977Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 086333b..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/replace) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index abe8730..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 303a99a..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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..d88a3c3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..976683d --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 5db827e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index f91e35c..b0b78bc 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.1.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-regexp": "^0.1.1", - "@stdlib/assert-is-regexp-string": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/process-read-stdin": "^0.1.1", - "@stdlib/regexp-eol": "^0.1.1", - "@stdlib/streams-node-stdin": "^0.1.1", - "@stdlib/string-base-replace": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-escape-regexp-string": "^0.1.1", - "@stdlib/utils-regexp-from-string": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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.1.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..f4e20da --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 77783bbc71f06d14a73e672207dd3a74d4780548 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 04:55:54 +0000 Subject: [PATCH 091/144] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96f8ebf..7416834 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.0", "@stdlib/streams-node-stdin": "^0.2.0", "@stdlib/string-base-replace": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/utils-escape-regexp-string": "^0.2.0", "@stdlib/utils-regexp-from-string": "^0.2.0" }, From 45ae3187ccd9c7f28708a97acd255962d5788de1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:19:35 +0000 Subject: [PATCH 092/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6242 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d88a3c3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.1.1-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 976683d..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f4e20da..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5075e7ecfb2dc20d99df59d119a1c18fe898823f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:19:54 +0000 Subject: [PATCH 093/144] 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 | 255 - .github/workflows/publish_cli.yml | 170 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 - test/test.js | 165 - 48 files changed, 6197 insertions(+), 4950 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 8125009..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/replace) 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 086333b..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/replace) 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 80b59f7..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e898b7d..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 corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..62a5b44 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.0-esm/index.mjs";function m(m,d,o){if(!t(m))throw new TypeError(i("invalid argument. First argument must be a string. Value: `%s`.",m));if(t(d))d=new RegExp(e(d),"g");else if(!r(d))throw new TypeError(i("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",d));if(!t(o)&&!s(o))throw new TypeError(i("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",o));return n(m,d,o)}export{m as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..976683d --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/string-format';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;6jBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,kEAAmEL,IAEjG,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,yFAA0FJ,IAExH,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,0FAA2FH,IAEzH,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 5db827e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 7416834..dd944b3 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.0", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-regexp": "^0.2.0", - "@stdlib/assert-is-regexp-string": "^0.2.0", - "@stdlib/assert-is-string": "^0.2.0", - "@stdlib/cli-ctor": "^0.1.1", - "@stdlib/fs-read-file": "^0.2.0", - "@stdlib/process-read-stdin": "^0.2.0", - "@stdlib/regexp-eol": "^0.2.0", - "@stdlib/streams-node-stdin": "^0.2.0", - "@stdlib/string-base-replace": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/utils-escape-regexp-string": "^0.2.0", - "@stdlib/utils-regexp-from-string": "^0.2.0" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.1.1", - "@stdlib/assert-is-windows": "^0.1.1", - "@stdlib/process-exec-path": "^0.1.1", - "@stdlib/string-capitalize": "^0.1.1", - "@stdlib/string-replace": "^0.1.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.1.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..0629aa3 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/stdin_error.js.txt b/test/fixtures/stdin_error.js.txt deleted file mode 100644 index 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 352526da42adb6fa4bedcfa0a8a3ea5db896e1e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 09:48:47 +0000 Subject: [PATCH 094/144] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c28fc90..b6ea5c9 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@esm/index.mjs'; +import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@v0.2.0-esm/index.mjs'; ``` #### replace( str, search, newval ) @@ -97,7 +97,7 @@ var out = replace( str, /([^\s]+)/gi, replacer ); - - - - From 2f7ceec9f10347938955c6ce21f7350da44e3667 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:15:23 +0000 Subject: [PATCH 098/144] 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 | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 48 files changed, 4862 insertions(+), 4950 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 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e898b7d..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 corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 06e7469..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^0.2.1", - "@stdlib/utils-regexp-from-string": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.0", - "@stdlib/assert-is-windows": "^0.2.1", - "@stdlib/process-exec-path": "^0.2.0", - "@stdlib/string-capitalize": "^0.2.0", - "@stdlib/string-replace": "^0.2.0", - "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.0" - }, - "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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 4d7a5f981c939655708ef58cb3394487d320879d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:47:32 +0000 Subject: [PATCH 099/144] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4176472..c7f0e27 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@esm/index.mjs'; +import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@v0.2.1-esm/index.mjs'; ``` #### replace( str, search, newval ) @@ -97,7 +97,7 @@ var out = replace( str, /([^\s]+)/gi, replacer ); - - - - From e78efa370128683d984a63faa6e5af9e51ee75e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 03:26:50 +0000 Subject: [PATCH 103/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 4953 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index 1a97f87..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T01:22:39.870Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e898b7d..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 corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 923924475970984bd174c1c660d0d3dc2587f036 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:37:09 +0000 Subject: [PATCH 104/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9aaf40e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 032e278..5204054 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.1", "@stdlib/streams-node-stdin": "^0.2.1", "@stdlib/string-base-replace": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-escape-regexp-string": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From d08fa64c9869030b69a746b4bcef2b51bc1681d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:29:14 +0000 Subject: [PATCH 105/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 64c238b..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2bf736b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From beda78fe46df33485ffc18451c329eb16aaa7a08 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:29:25 +0000 Subject: [PATCH 106/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 4956 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index f1ba77b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T01:11:02.294Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 42600ec534d05119970a1f1540e710672d197507 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 21:43:09 +0000 Subject: [PATCH 107/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9aaf40e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 032e278..5204054 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.1", "@stdlib/streams-node-stdin": "^0.2.1", "@stdlib/string-base-replace": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-escape-regexp-string": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 1caf6a14cdb62be037df37108d4211ca39425c90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:34:42 +0000 Subject: [PATCH 108/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 64c238b..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2bf736b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 164fbcadce8fd59854b7c1832b2de988a3b4feb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:34:57 +0000 Subject: [PATCH 109/144] 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 | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 48 files changed, 4862 insertions(+), 4957 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 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 2f3b2e230ce1a97d660145b208e9c6b154c6eca3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:37:39 +0000 Subject: [PATCH 110/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9aaf40e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 032e278..5204054 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.1", "@stdlib/streams-node-stdin": "^0.2.1", "@stdlib/string-base-replace": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-escape-regexp-string": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 20273f99f7999702d42358d6f455a3ec19f3c572 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:13:57 +0000 Subject: [PATCH 111/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 64c238b..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2bf736b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 57b29630c9b3eb77be670b8c56caf5bff9acda0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:14:21 +0000 Subject: [PATCH 112/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 4963 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index 168a2c2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T01:11:53.437Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From fc838c3e5231de591fa38ed87b17d48b4291b5f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:47:14 +0000 Subject: [PATCH 113/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9aaf40e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 032e278..5204054 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.1", "@stdlib/streams-node-stdin": "^0.2.1", "@stdlib/string-base-replace": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-escape-regexp-string": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 7dd89245ba4dd818083d50ec1473f6d223532764 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:07:14 +0000 Subject: [PATCH 114/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 64c238b..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2bf736b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 314fb0cc3b6ceae3d677d6ec60f86b11ac1931d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:07:34 +0000 Subject: [PATCH 115/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 4963 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index 1d0cdcc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T01:22:33.509Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2381765..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){ -var o=require('@stdlib/utils-escape-regexp-string/dist'),g=require('@stdlib/assert-is-function/dist'),t=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-regexp/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist'),p=require('@stdlib/string-base-replace/dist');function v(e,r,i){if(!t(e))throw new TypeError(u('1PJ3F',e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u('1PJAT',r));if(!t(i)&&!g(i))throw new TypeError(u('1PJAU',i));return p(e,r,i)}n.exports=v -});var f=a();module.exports=f; -/** @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 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 2d46627a5e23e29709ca2299f784f0e0c6dfbf66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:45:12 +0000 Subject: [PATCH 116/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5db827e..9aaf40e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 032e278..5204054 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.1", "@stdlib/streams-node-stdin": "^0.2.1", "@stdlib/string-base-replace": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-escape-regexp-string": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 6f6997d6df686b3b45e4b0db0e77c7e19f4fcc98 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:08:00 +0000 Subject: [PATCH 117/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 64c238b..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2bf736b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4000f168ea5d30af665cfee4c53bdb5b54003200 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:08:14 +0000 Subject: [PATCH 118/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 38 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 5014 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/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/.keepalive b/.github/.keepalive deleted file mode 100644 index e8702fa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T01:20:12.271Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 74db840..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..64c238b --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 9aaf40e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..2bf736b --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 75962a2f9f66323869298f0fda901d7d7cf4b07f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jul 2024 17:18:17 +0000 Subject: [PATCH 119/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 032e278..5204054 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.1", "@stdlib/streams-node-stdin": "^0.2.1", "@stdlib/string-base-replace": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-escape-regexp-string": "^0.2.1", "@stdlib/utils-regexp-from-string": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 7e080ef64e1aa915c73e13a15e18d1597221a93a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jul 2024 17:30:21 +0000 Subject: [PATCH 120/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 64c238b..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2bf736b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7316979de24e68cf1156c58c46070ce2f1b670f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jul 2024 17:30:35 +0000 Subject: [PATCH 121/144] 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 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 106 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 48 files changed, 4862 insertions(+), 5081 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 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..151a1a8 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index 5204054..56d1f60 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.1", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^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..413c4ac --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 96fb892b321f203ad02128f488cc9adb7b9d4ca5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 01:59:02 +0000 Subject: [PATCH 122/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 0b4ec82..a6ed71e 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.2", "@stdlib/streams-node-stdin": "^0.2.2", "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-escape-regexp-string": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 070320fc0002bd5f91afce981c520262c48727d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:05:12 +0000 Subject: [PATCH 123/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 151a1a8..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.1-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a2f4c0..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 413c4ac..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5b43d489006953ae2fefa5ed97c71273c1f7f814 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:05:28 +0000 Subject: [PATCH 124/144] 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 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 269 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 48 files changed, 4862 insertions(+), 5244 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 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index a6ed71e..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^0.2.2", - "@stdlib/assert-is-regexp-string": "^0.2.1", - "@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.1", - "@stdlib/regexp-eol": "^0.2.2", - "@stdlib/streams-node-stdin": "^0.2.2", - "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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.1", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/process-exec-path": "^0.2.1", - "@stdlib/string-capitalize": "^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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 870f08b63d348837ff84cbafff97b7dceade97a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:11:25 +0000 Subject: [PATCH 125/144] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index acb59f1..b2a0567 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ limitations under the License. ## Usage ```javascript -import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@esm/index.mjs'; +import replace from 'https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@v0.2.2-esm/index.mjs'; ``` #### replace( str, search, newval ) @@ -97,7 +97,7 @@ var out = replace( str, /([^\s]+)/gi, replacer ); - - - - From bf9e7f40bc69f3b67cd45692a09e91ff801cb9a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 03:38:24 +0000 Subject: [PATCH 129/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 198 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 5176 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index d295d7b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T01:23:28.503Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index ce63c99..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^0.3.0", - "@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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From c99782d2b138f844e87c6c9e5227522ef9b4b9cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 16:28:25 +0000 Subject: [PATCH 130/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 6d1bd3b..ce63c99 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.2", "@stdlib/streams-node-stdin": "^0.2.2", "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-escape-regexp-string": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 7e4f9427b9f4f20c18bb4a3397d8b84c8dc67d0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:34:03 +0000 Subject: [PATCH 131/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4dde553..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a2f4c0..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0cf760f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9475d353b7f83b129687a8baf4470cc33c892552 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:34:16 +0000 Subject: [PATCH 132/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 269 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 5247 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index 29982ae..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T16:09:00.438Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index ce63c99..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^0.3.0", - "@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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 55b7ea6d30bc724cf47ae162517dbb316c87ccc7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 01:55:32 +0000 Subject: [PATCH 133/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 6d1bd3b..ce63c99 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.2", "@stdlib/streams-node-stdin": "^0.2.2", "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-escape-regexp-string": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From ff896f1dcd72ee7911bd6f617fa06f3c2ce3b6ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:29:46 +0000 Subject: [PATCH 134/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4dde553..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a2f4c0..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0cf760f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 85b5f925134f571c1b1f3be465ab6913299c97c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:29:59 +0000 Subject: [PATCH 135/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 269 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 5247 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index 32d79ad..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T01:30:18.137Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index ce63c99..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^0.3.0", - "@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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From f8ad245a8c70e8c3c081c98894b04fa269916095 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 01:59:14 +0000 Subject: [PATCH 136/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 6d1bd3b..ce63c99 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.2", "@stdlib/streams-node-stdin": "^0.2.2", "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-escape-regexp-string": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 7a3624a2a7f6940f361fee16b806fae8d5482364 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:23:21 +0000 Subject: [PATCH 137/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4dde553..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a2f4c0..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0cf760f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0463bc5dad4da9322c8b421613a93fe4714e9d10 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:23:33 +0000 Subject: [PATCH 138/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 269 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 5247 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index 626faf0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T01:36:28.595Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index ce63c99..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^0.3.0", - "@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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 5cb0cf75cc5a3dee55f491b85696741c20a099a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 01:55:51 +0000 Subject: [PATCH 139/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 6d1bd3b..ce63c99 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.2", "@stdlib/streams-node-stdin": "^0.2.2", "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-escape-regexp-string": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 0209dbe7726119224f7a73ec7c5028fc77769933 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:13:44 +0000 Subject: [PATCH 140/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4dde553..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a2f4c0..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0cf760f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 35c5903a2845d68ee96ce91e66cc7d2c878c0651 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:13:56 +0000 Subject: [PATCH 141/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 269 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 49 files changed, 4862 insertions(+), 5247 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 .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/.keepalive b/.github/.keepalive deleted file mode 100644 index ffee293..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T01:33:27.934Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index ce63c99..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^0.3.0", - "@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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); From 230bc49ee5bb22989c81fd19d39dbce4acdc6326 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 02:02:39 +0000 Subject: [PATCH 142/144] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d86a4d6..56b8d1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var rescape = require( '@stdlib/utils-escape-regexp-string' ); var isFunction = require( '@stdlib/assert-is-function' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var base = require( '@stdlib/string-base-replace' ); @@ -65,15 +65,15 @@ var base = require( '@stdlib/string-base-replace' ); */ function replace( str, search, newval ) { if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + throw new TypeError( format( '1PJ3F', str ) ); } if ( isString( search ) ) { search = new RegExp( rescape( search ), 'g' ); } else if ( !isRegExp( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) ); + throw new TypeError( format( '1PJAT', search ) ); } if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) ); + throw new TypeError( format( '1PJAU', newval ) ); } return base( str, search, newval ); } diff --git a/package.json b/package.json index 6d1bd3b..ce63c99 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/regexp-eol": "^0.2.2", "@stdlib/streams-node-stdin": "^0.2.2", "@stdlib/string-base-replace": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-escape-regexp-string": "^0.2.2", "@stdlib/utils-regexp-from-string": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From ea796757265514fbae25ae8733ec326811fd6485 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:29:14 +0000 Subject: [PATCH 143/144] Remove files --- index.d.ts | 60 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4907 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 bbb241f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* Replaces search occurrences with a replacement string. -* -* ## Notes -* -* - When provided a `string` as the `search` value, the function replaces **all** occurrences. To remove only the first match, use a regular expression. -* -* @param str - input string -* @param search - search expression -* @param newval - replacement value or function -* @returns new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -declare function repeat( str: string, search: string | RegExp, newval: string | Function ): string; - - -// EXPORTS // - -export = repeat; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4dde553..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7a2f4c0..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0cf760f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5e101c70c6d8ff80698157f06dbeead5e1445cf4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:29:35 +0000 Subject: [PATCH 144/144] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 269 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 128 +- SECURITY.md | 5 - benchmark/benchmark.js | 197 - bin/cli | 114 - branches.md | 60 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 42 - docs/types/test.ts | 60 - docs/usage.txt | 10 - etc/cli_opts.json | 19 - examples/index.js | 38 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 45 - lib/main.js | 84 - package.json | 73 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/stdin_error.js.txt | 33 - test/test.cli.js | 293 -- test/test.js | 165 - 50 files changed, 4862 insertions(+), 5352 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 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b766c5b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T01:39:41.848Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8125009..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/replace) 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 086333b..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/replace) 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 b3651d1..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: '35 11 * * 1' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 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 + + ```
-
- @@ -242,7 +140,7 @@ fee ## 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 626d976..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 replace = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', 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+'::regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, re, 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+'::replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = replace( str, 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); - -bench( pkg+'::builtin,string', function benchmark( b ) { - var values; - var out; - var str; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', 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+'::builtin,regexp', function benchmark( b ) { - var values; - var out; - var str; - var re; - var i; - - values = [ - 'abc', - 'def', - 'hig' - ]; - str = 'To be, or not to be, that is the question.'; - re = /be/g; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( re, 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+'::builtin,replacer', function benchmark( b ) { - var out; - var str; - var i; - - str = 'To be, or not to be, that is the question.'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = str.replace( 'be', replacer ); - 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(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 6a8df66..0000000 --- a/bin/cli +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( './../lib' ); - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var search; - var split; - var flags; - var args; - var cli; - - // 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; - } - - // Get any provided command-line arguments: - args = cli.args(); - - search = flags.search; - if ( isRegExpString( search ) ) { - search = reFromString( search ); - } - - // 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 ); - } - console.log( replace( args[ 0 ], search, flags.newval ) ); // eslint-disable-line no-console - - /** - * 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(); - } - for ( i = 0; i < lines.length; i++ ) { - console.log( replace( lines[ i ], search, flags.newval ) ); // eslint-disable-line no-console - } - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index d51a92f..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/replace" -%% click B href "https://github.com/stdlib-js/string-replace/tree/main" -%% click C href "https://github.com/stdlib-js/string-replace/tree/production" -%% click D href "https://github.com/stdlib-js/string-replace/tree/esm" -%% click E href "https://github.com/stdlib-js/string-replace/tree/deno" -%% click F href "https://github.com/stdlib-js/string-replace/tree/umd" -%% click G href "https://github.com/stdlib-js/string-replace/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace -[production-url]: https://github.com/stdlib-js/string-replace/tree/production -[deno-url]: https://github.com/stdlib-js/string-replace/tree/deno -[deno-readme]: https://github.com/stdlib-js/string-replace/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/string-replace/tree/umd -[umd-readme]: https://github.com/stdlib-js/string-replace/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/string-replace/tree/esm -[esm-readme]: https://github.com/stdlib-js/string-replace/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/string-replace/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 f4bc499..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import repeat from '../docs/types/index'; -export = repeat; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 88a3463..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=s(function(q,n){"use strict";var o=require("@stdlib/utils-escape-regexp-string"),g=require("@stdlib/assert-is-function"),t=require("@stdlib/assert-is-string").isPrimitive,m=require("@stdlib/assert-is-regexp"),u=require("@stdlib/string-format"),p=require("@stdlib/string-base-replace");function v(e,r,i){if(!t(e))throw new TypeError(u("invalid argument. First argument must be a string. Value: `%s`.",e));if(t(r))r=new RegExp(o(r),"g");else if(!m(r))throw new TypeError(u("invalid argument. Second argument must be a string or regular expression. Value: `%s`.",r));if(!t(i)&&!g(i))throw new TypeError(u("invalid argument. Third argument must be a string or replacement function. Value: `%s`.",i));return p(e,r,i)}n.exports=v});var f=a();module.exports=f; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index f1bf4f2..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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\nvar format = require( '@stdlib/string-format' );\nvar base = require( '@stdlib/string-base-replace' );\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a string or regular expression. Value: `%s`.', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a string or replacement function. Value: `%s`.', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\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,EAAU,QAAS,oCAAqC,EACxDC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,6BAA8B,EAsClD,SAASC,EAASC,EAAKC,EAAQC,EAAS,CACvC,GAAK,CAACP,EAAUK,CAAI,EACnB,MAAM,IAAI,UAAWH,EAAQ,kEAAmEG,CAAI,CAAE,EAEvG,GAAKL,EAAUM,CAAO,EACrBA,EAAS,IAAI,OAAQR,EAASQ,CAAO,EAAG,GAAI,UACjC,CAACL,EAAUK,CAAO,EAC7B,MAAM,IAAI,UAAWJ,EAAQ,yFAA0FI,CAAO,CAAE,EAEjI,GAAK,CAACN,EAAUO,CAAO,GAAK,CAACR,EAAYQ,CAAO,EAC/C,MAAM,IAAI,UAAWL,EAAQ,0FAA2FK,CAAO,CAAE,EAElI,OAAOJ,EAAME,EAAKC,EAAQC,CAAO,CAClC,CAKAV,EAAO,QAAUO,IC5CjB,IAAII,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "rescape", "isFunction", "isString", "isRegExp", "format", "base", "replace", "str", "search", "newval", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d34f97d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,42 +0,0 @@ - -{{alias}}( str, search, newval ) - Replaces search occurrences with a replacement string. - - When provided a string as the search value, the function replaces *all* - occurrences. To remove only the first match, use a regular expression. - - Parameters - ---------- - str: string - Input string. - - search: string|RegExp - Search expression. - - newval: string|Function - Replacement value or function. - - Returns - ------- - out: string - String containing replacement(s). - - Examples - -------- - // Standard usage: - > var out = {{alias}}( 'beep', 'e', 'o' ) - 'boop' - - // Replacer function: - > function replacer( match, p1 ) { return '/'+p1+'/'; }; - > var str = 'Oranges and lemons'; - > out = {{alias}}( str, /([^\s]+)/gi, replacer ) - '/Oranges/ /and/ /lemons/' - - // Replace only first match: - > out = {{alias}}( 'beep', /e/, 'o' ) - 'boep' - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a9c5324..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 replace = require( './index' ); - - -// TESTS // - -// The function returns a string... -{ - replace( 'abd', 'd', 'c' ); // $ExpectType string - replace( 'abd', /[a-z]/, '1' ); // $ExpectType string - replace( 'abd', /[a-z]/, (): string => 'z' ); // $ExpectType string -} - -// The compiler throws an error if the function is provided arguments having invalid types... -{ - replace( true, 'd', 'a' ); // $ExpectError - replace( false, 'd', 'a' ); // $ExpectError - replace( 3, 'd', 'a' ); // $ExpectError - replace( [], 'd', 'a' ); // $ExpectError - replace( {}, 'd', 'a' ); // $ExpectError - replace( ( x: number ): number => x, 'd', 'a' ); // $ExpectError - - replace( 'abd', true, 'c' ); // $ExpectError - replace( 'abd', false, 'c' ); // $ExpectError - replace( 'abd', 5, 'c' ); // $ExpectError - replace( 'abd', [], 'c' ); // $ExpectError - replace( 'abd', {}, 'c' ); // $ExpectError - replace( 'abd', ( x: number ): number => x, 'c' ); // $ExpectError - - replace( 'abd', 'd', true ); // $ExpectError - replace( 'abd', 'd', false ); // $ExpectError - replace( 'abd', 'd', 5 ); // $ExpectError - replace( 'abd', 'd', [] ); // $ExpectError - replace( 'abd', 'd', {} ); // $ExpectError - replace( 'abd', 'd', /[a-z]/ ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - replace(); // $ExpectError - replace( 'abc' ); // $ExpectError - replace( 'abc', 'a' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 9e7e21b..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: replace [options] [] --search= --newval= - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --newval string Replacement string. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 00a4539..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "string": [ - "search", - "newval", - "split" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 42da525..0000000 --- a/examples/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 capitalize = require( '@stdlib/string-capitalize' ); -var replace = require( './../lib' ); - -var out = replace( 'beep', 'e', 'o' ); -console.log( out ); -// => 'boop' - -out = replace( 'Hello World', /world/i, 'Mr. President' ); -console.log( out ); -// => 'Hello Mr. President' - -function replacer( match, p1 ) { - return capitalize( p1 ); -} -var str = 'Oranges and lemons say the bells of St. Clement\'s'; -out = replace( str, /([^\s]*)/gi, replacer ); -console.log( out ); -// => 'Oranges And Lemons Say The Bells Of St. Clement\'s' 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..4dde553 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-escape-regexp-string@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-regexp@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-base-replace@v0.2.2-esm/index.mjs";function d(d,m,o){if(!t(d))throw new TypeError(i("1PJ3F",d));if(t(m))m=new RegExp(s(m),"g");else if(!r(m))throw new TypeError(i("1PJAT",m));if(!t(o)&&!e(o))throw new TypeError(i("1PJAU",o));return n(d,m,o)}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7a2f4c0 --- /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) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 rescape from '@stdlib/utils-escape-regexp-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isRegExp from '@stdlib/assert-is-regexp';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport base from '@stdlib/string-base-replace';\n\n\n// MAIN //\n\n/**\n* Replaces search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument argument must be a string or regular expression\n* @throws {TypeError} third argument must be a string or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* import capitalize from '@stdlib/string-capitalize';\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer );\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( '1PJ3F', str ) );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = new RegExp( rescape( search ), 'g' );\n\t} else if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( format( '1PJAT', search ) );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( format( '1PJAU', newval ) );\n\t}\n\treturn base( str, search, newval );\n}\n\n\n// EXPORTS //\n\nexport default replace;\n"],"names":["replace","str","search","newval","isString","TypeError","format","RegExp","rescape","isRegExp","isFunction","base"],"mappings":";;skBAiEA,SAASA,EAASC,EAAKC,EAAQC,GAC9B,IAAMC,EAAUH,GACf,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,GAAKG,EAAUF,GACdA,EAAS,IAAIK,OAAQC,EAASN,GAAU,UAClC,IAAMO,EAAUP,GACtB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,IAAME,EAAUD,KAAaO,EAAYP,GACxC,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,OAAOQ,EAAMV,EAAKC,EAAQC,EAC3B"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a4ad615..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Replace search occurrences with a replacement string. -* -* @module @stdlib/string-replace -* -* @example -* var replace = require( '@stdlib/string-replace' ); -* -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* str = 'Hello World'; -* out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -*/ - -// 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 56b8d1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var rescape = require( '@stdlib/utils-escape-regexp-string' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert-is-regexp' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var base = require( '@stdlib/string-base-replace' ); - - -// MAIN // - -/** -* Replaces search occurrences with a replacement string. -* -* @param {string} str - input string -* @param {(string|RegExp)} search - search expression -* @param {(string|Function)} newval - replacement value or function -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument argument must be a string or regular expression -* @throws {TypeError} third argument must be a string or function -* @returns {string} new string containing replacement(s) -* -* @example -* var str = 'beep'; -* var out = replace( str, 'e', 'o' ); -* // returns 'boop' -* -* @example -* var str = 'Hello World'; -* var out = replace( str, /world/i, 'Mr. President' ); -* // returns 'Hello Mr. President' -* -* @example -* var capitalize = require( '@stdlib/string-capitalize' ); -* -* var str = 'Oranges and lemons say the bells of St. Clement\'s'; -* -* function replacer( match, p1 ) { -* return capitalize( p1 ); -* } -* -* var out = replace( str, /([^\s]*)/gi, replacer ); -* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s' -*/ -function replace( str, search, newval ) { - if ( !isString( str ) ) { - throw new TypeError( format( '1PJ3F', str ) ); - } - if ( isString( search ) ) { - search = new RegExp( rescape( search ), 'g' ); - } else if ( !isRegExp( search ) ) { - throw new TypeError( format( '1PJAT', search ) ); - } - if ( !isString( newval ) && !isFunction( newval ) ) { - throw new TypeError( format( '1PJAU', newval ) ); - } - return base( str, search, newval ); -} - - -// EXPORTS // - -module.exports = replace; diff --git a/package.json b/package.json index ce63c99..cc042e4 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Replace search occurrences with a replacement 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": { - "replace": "./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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-regexp": "^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-replace": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-escape-regexp-string": "^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-capitalize": "^0.3.0", - "@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..0cf760f --- /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 0c1476f..0000000 --- a/test/fixtures/stdin_error.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 42a0cb5..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,293 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 replace = require( '@stdlib/string-replace' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -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 prints a string where all occurrences of a string search value are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--search=e\'; process.argv[ 3 ] = \'--newval=o\'; process.argv[ 4 ] = \'beep\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'boop\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface prints a string where all matches of a regular expression are replaced', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--newval=x\'; process.argv[ 3 ] = \'--search="/[eaoui]/g"\'; process.argv[ 4 ] = \'Hello World!\'; require( \''+fpath+'\' );"' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var str; - if ( error ) { - t.fail( error.message ); - } else { - str = stdout.toString(); - t.strictEqual( str === 'Hxllx Wxrld!\n', true, 'prints expected value to `stdout`' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - t.end(); - } -}); - -tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { - var cmd = [ - 'printf "b123p\nb234"', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'bp\nb\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split \'\t\'' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\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 \'a11y\ti18n\ta16z\'', - '|', - EXEC_PATH, - fpath, - '--search=/[0-9]/g', - '--newval=""', - '--split=/\\\\t/' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), 'ay\nin\naz\n', 'expected value' ); - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - } - 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 d0a4242..0000000 --- a/test/test.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var replace = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof replace, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if the first argument is not a string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {}, - function noop() {}, - / /g - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( value, '', '' ); - }; - } -}); - -tape( 'the function throws an error if the second argument is not a string or regular expression', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - 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() { - replace( 'string', value, '' ); - }; - } -}); - -tape( 'the function throws an error if the third argument is not a function or string', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - false, - void 0, - NaN, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replace( 'string', 'str', value ); - }; - } -}); - -tape( 'the function replaces all occurrences of a string search value', function test( t ) { - var out; - - out = replace( 'abc abc abc', 'b', '' ); - t.equal( out, 'ac ac ac', 'returns expected value' ); - - out = replace( 'abc abc abc', 'b', 'cd' ); - t.equal( out, 'acdc acdc acdc', 'returns expected value' ); - - out = replace( 'Et tu, Brute?', 'Brute?', 'Caesar?' ); - t.equal( out, 'Et tu, Caesar?', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function replaces matches of a regular expression', function test( t ) { - var expected; - var out; - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/, '' ); - expected = 'acDeFgHiJkLmNoPqRsTuVwXYZ'; - t.equal( out, expected, 'replaces letters matching the regular expression (first occurrence)' ); - - out = replace( 'aBcDeFgHiJkLmNoPqRsTuVwXYZ', /[A-Z]+/g, '' ); - expected = 'acegikmoqsuw'; - t.equal( out, expected, 'replaces letters matching the regular expression (global)' ); - - t.end(); -}); - -tape( 'the function replaces matches with values returned by a replacer function', function test( t ) { - var expected; - var out; - var str; - - str = 'Oranges and lemons say the bells of St. Clement\'s'; - out = replace( str, /([^\s]+)/gi, replacer ); - - expected = '/Oranges/ /and/ /lemons/ /say/ /the/ /bells/ /of/ /St./ /Clement\'s/'; - t.equal( out, expected, 'replaces matches using replacer function' ); - - t.end(); - - function replacer( match, p1 ) { - return '/' + p1 + '/'; - } -});