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
114 changes: 114 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,114 @@
<!--

@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 'helloworld'
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```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 ''
```

</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 -->

81 changes: 81 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,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();
});
29 changes: 29 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,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
--------

38 changes: 38 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,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;

56 changes: 56 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,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
}

45 changes: 45 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,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 );
// => ''
Loading