Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!--

@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.

-->

# concat

> Concatenate two strings.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var concat = require( '@stdlib/string/base/concat' );
```

#### concat( str1, str2 )

Concatenates two strings.

```javascript
var str = concat( 'Hello ', 'World!' );
// returns 'Hello World!'
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var concat = require( '@stdlib/string/base/concat' );

var str = concat( 'Hello ', 'World!' );
// returns 'Hello World!'

str = concat( 'Beep ', 'Boop' );
// returns 'Beep Boop'

str = concat( '', 'World!' );
// returns 'World!'

str = concat( 'Hello ', '' );
// returns 'Hello '

str = concat( '', '' );
// returns ''
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/string/base/lowercase`][@stdlib/string/base/lowercase]</span><span class="delimiter">: </span><span class="description">convert a string to lowercase.</span>
- <span class="package-name">[`@stdlib/string/base/uppercase`][@stdlib/string/base/uppercase]</span><span class="delimiter">: </span><span class="description">convert a string to uppercase.</span>

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

[@stdlib/string/base/lowercase]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/base/lowercase

[@stdlib/string/base/uppercase]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/base/uppercase

<!-- </related-links> -->

</section>

<!-- /.links -->
93 changes: 93 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* @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 values1;
var values2;
var out;
var i;

values1 = [
'Hello ',
'Beep ',
'Foo '
];
values2 = [
'World!',
'Boop',
'Bar'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = concat( values1[ i%values1.length ], values2[ i%values2.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', function benchmark( b ) {
var values1;
var values2;
var out;
var i;

values1 = [
'Hello ',
'Beep ',
'Foo '
];
values2 = [
'World!',
'Boop',
'Bar'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = values1[ i%values1.length ].concat( values2[ i%values2.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();
});
25 changes: 25 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

{{alias}}( str1, str2 )
Concatenates two strings.

Parameters
----------
str1: string
First string.

str2: string
Second string.

Returns
-------
out: string
Concatenated string.

Examples
--------
> var out = {{alias}}( 'Hello ', 'World!' )
'Hello World!'

See Also
--------

37 changes: 37 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* @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 'Hello World!'
*/
declare function concat( str1: string, str2: string ): string;


// EXPORTS //

export = concat;
59 changes: 59 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* @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( 'Beep ', 'Boop' ); // $ExpectType string
concat( '', '' ); // $ExpectType string
}

// The compiler throws an error if the function is provided a first argument that is not a string...
{
concat( true, 'abc' ); // $ExpectError
concat( false, 'abc' ); // $ExpectError
concat( null, 'abc' ); // $ExpectError
concat( undefined, 'abc' ); // $ExpectError
concat( 5, 'abc' ); // $ExpectError
concat( [], 'abc' ); // $ExpectError
concat( {}, 'abc' ); // $ExpectError
concat( ( x: number ): number => x, 'abc' ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument that is not a string...
{
concat( 'abc', true ); // $ExpectError
concat( 'abc', false ); // $ExpectError
concat( 'abc', null ); // $ExpectError
concat( 'abc', undefined ); // $ExpectError
concat( 'abc', 5 ); // $ExpectError
concat( 'abc', [] ); // $ExpectError
concat( 'abc', {} ); // $ExpectError
concat( 'abc', ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided insufficient arguments...
{
concat(); // $ExpectError
concat( 'abc' ); // $ExpectError
}
41 changes: 41 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/examples/index.js
Original file line number Diff line number Diff line change
@@ -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';

var concat = require( './../lib' );

var str = concat( 'Hello ', 'World!' );
console.log( str );
// => 'Hello World!'

str = concat( 'Beep ', 'Boop' );
console.log( str );
// => 'Beep Boop'

str = concat( '', 'World!' );
console.log( str );
// => 'World!'

str = concat( 'Hello ', '' );
console.log( str );
// => 'Hello '

str = concat( '', '' );
console.log( str );
// => ''
Loading