From 1b7991627ddea6f4b32fedadf5b376b5016574bf Mon Sep 17 00:00:00 2001 From: Muzaffar0076 Date: Sun, 16 Nov 2025 05:53:31 +0530 Subject: [PATCH] feat: add string/base/concat Add package to concatenate two strings with fixed arity. This package wraps String.prototype.concat to provide a fixed-arity function that takes exactly two string arguments, unlike the native method which accepts an arbitrary number of arguments. Closes #8520 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/string/base/concat/README.md | 114 ++++++++++++++++++ .../string/base/concat/benchmark/benchmark.js | 81 +++++++++++++ .../@stdlib/string/base/concat/docs/repl.txt | 29 +++++ .../string/base/concat/docs/types/index.d.ts | 38 ++++++ .../string/base/concat/docs/types/test.ts | 56 +++++++++ .../string/base/concat/examples/index.js | 45 +++++++ .../@stdlib/string/base/concat/lib/index.js | 40 ++++++ .../@stdlib/string/base/concat/lib/main.js | 41 +++++++ .../@stdlib/string/base/concat/package.json | 65 ++++++++++ .../@stdlib/string/base/concat/test/test.js | 90 ++++++++++++++ 10 files changed, 599 insertions(+) create mode 100644 lib/node_modules/@stdlib/string/base/concat/README.md create mode 100644 lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/concat/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/concat/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/concat/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/concat/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/concat/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/concat/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/concat/package.json create mode 100644 lib/node_modules/@stdlib/string/base/concat/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/concat/README.md b/lib/node_modules/@stdlib/string/base/concat/README.md new file mode 100644 index 000000000000..ff2986dff57d --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/README.md @@ -0,0 +1,114 @@ + + +# concat + +> Concatenate two strings. + +
+ +
+ + + +
+ +## Usage + +```javascript +var concat = require( '@stdlib/string/base/concat' ); +``` + +#### concat( str1, str2 ) + +Concatenates two strings. + +```javascript +var str = concat( 'hello', 'world' ); +// returns 'helloworld' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var concat = require( '@stdlib/string/base/concat' ); + +var str = concat( 'hello', 'world' ); +// returns 'helloworld' + +str = concat( 'foo', 'bar' ); +// returns 'foobar' + +str = concat( 'beep', ' boop' ); +// returns 'beep boop' + +str = concat( '', 'baz' ); +// returns 'baz' + +str = concat( 'qux', '' ); +// returns 'qux' + +str = concat( '', '' ); +// returns '' +``` + +
+ + + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js new file mode 100644 index 000000000000..eb295b045be1 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 concat = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + [ 'hello', 'world' ], + [ 'foo', 'bar' ], + [ 'beep', 'boop' ] + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = concat(values[ i%values.length ][ 0 ], values[ i%values.length ][ 1 ]); + if ( typeof out !== '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', function benchmark( b ) { + var values; + var out; + var i; + + values = [ + [ 'hello', 'world' ], + [ 'foo', 'bar' ], + [ 'beep', 'boop' ] + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = values[ i%values.length ][ 0 ].concat(values[ i%values.length ][ 1 ]); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/concat/docs/repl.txt b/lib/node_modules/@stdlib/string/base/concat/docs/repl.txt new file mode 100644 index 000000000000..7977f1302f99 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( str1, str2 ) + Concatenates two strings. + + Parameters + ---------- + str1: string + First input string. + + str2: string + Second input string. + + Returns + ------- + out: string + Concatenated string. + + Examples + -------- + > var out = {{alias}}( 'hello', 'world' ) + 'helloworld' + > out = {{alias}}( 'foo', 'bar' ) + 'foobar' + > out = {{alias}}( '', 'baz' ) + 'baz' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/concat/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/concat/docs/types/index.d.ts new file mode 100644 index 000000000000..df61b61db496 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/docs/types/index.d.ts @@ -0,0 +1,38 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 + +/** +* Concatenates two strings. +* +* @param str1 - first string +* @param str2 - second string +* @returns concatenated string +* +* @example +* var str = concat( 'hello', 'world' ); +* // returns 'helloworld' +*/ +declare function concat( str1: string, str2: string ): string; + + +// EXPORTS // + +export = concat; + diff --git a/lib/node_modules/@stdlib/string/base/concat/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/concat/docs/types/test.ts new file mode 100644 index 000000000000..828d6a80ea27 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 concat = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + concat( 'hello', 'world' ); // $ExpectType string + concat( 'foo', 'bar' ); // $ExpectType string + concat( 'beep' as string, 'boop' as string ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string... +{ + concat( true, 'world' ); // $ExpectError + concat( false, 'world' ); // $ExpectError + concat( null, 'world' ); // $ExpectError + concat( undefined, 'world' ); // $ExpectError + concat( 5, 'world' ); // $ExpectError + concat( [], 'world' ); // $ExpectError + concat( {}, 'world' ); // $ExpectError + concat( ( x: number ): number => x, 'world' ); // $ExpectError + concat( 'hello', true ); // $ExpectError + concat( 'hello', false ); // $ExpectError + concat( 'hello', null ); // $ExpectError + concat( 'hello', undefined ); // $ExpectError + concat( 'hello', 5 ); // $ExpectError + concat( 'hello', [] ); // $ExpectError + concat( 'hello', {} ); // $ExpectError + concat( 'hello', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + concat(); // $ExpectError + concat( 'hello' ); // $ExpectError +} + diff --git a/lib/node_modules/@stdlib/string/base/concat/examples/index.js b/lib/node_modules/@stdlib/string/base/concat/examples/index.js new file mode 100644 index 000000000000..7057240030c1 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR 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 concat = require( './../lib' ); + +var str = concat( 'hello', 'world' ); +console.log( str ); +// => 'helloworld' + +str = concat( 'foo', 'bar' ); +console.log( str ); +// => 'foobar' + +str = concat( 'beep', ' boop' ); +console.log( str ); +// => 'beep boop' + +str = concat( '', 'baz' ); +console.log( str ); +// => 'baz' + +str = concat( 'qux', '' ); +console.log( str ); +// => 'qux' + +str = concat( '', '' ); +console.log( str ); +// => '' diff --git a/lib/node_modules/@stdlib/string/base/concat/lib/index.js b/lib/node_modules/@stdlib/string/base/concat/lib/index.js new file mode 100644 index 000000000000..2a1bdffd4e74 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Concatenate two strings. +* +* @module @stdlib/string/base/concat +* +* @example +* var concat = require( '@stdlib/string/base/concat' ); +* +* var str = concat( 'hello', 'world' ); +* // returns 'helloworld' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/concat/lib/main.js b/lib/node_modules/@stdlib/string/base/concat/lib/main.js new file mode 100644 index 000000000000..ec1af93a6e31 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/lib/main.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Concatenates two strings. +* +* @param {string} str1 - first string +* @param {string} str2 - second string +* @returns {string} concatenated string +* +* @example +* var str = concat( 'hello', 'world' ); +* // returns 'helloworld' +*/ +function concat( str1, str2 ) { + return str1.concat( str2 ); +} + + +// EXPORTS // + +module.exports = concat; diff --git a/lib/node_modules/@stdlib/string/base/concat/package.json b/lib/node_modules/@stdlib/string/base/concat/package.json new file mode 100644 index 000000000000..22168a574576 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/string/base/concat", + "version": "0.0.0", + "description": "Concatenate two strings.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "base", + "concat", + "concatenate", + "join", + "string", + "str" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/concat/test/test.js b/lib/node_modules/@stdlib/string/base/concat/test/test.js new file mode 100644 index 000000000000..287b49eddb3b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/concat/test/test.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var concat = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof concat, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function concatenates two strings', function test( t ) { + var expected; + var actual; + var str1; + var str2; + + str1 = 'hello'; + str2 = 'world'; + expected = 'helloworld'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'concatenates strings' ); + + str1 = 'foo'; + str2 = 'bar'; + expected = 'foobar'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'concatenates strings' ); + + str1 = ''; + str2 = 'baz'; + expected = 'baz'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'handles empty first string' ); + + str1 = 'qux'; + str2 = ''; + expected = 'qux'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'handles empty second string' ); + + str1 = ''; + str2 = ''; + expected = ''; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'handles both empty strings' ); + + str1 = 'a'; + str2 = 'b'; + expected = 'ab'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'handles single character strings' ); + + str1 = 'beep'; + str2 = ' boop'; + expected = 'beep boop'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'handles strings with spaces' ); + + str1 = '$**_'; + str2 = 'beep_**$'; + expected = '$**_beep_**$'; + actual = concat( str1, str2 ); + t.strictEqual( actual, expected, 'handles strings with special characters' ); + + t.end(); +});