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 )

Converts a string to concat.

```javascript
var out = concat('beep', 'boop');
// returns 'beepboop'
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

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

var str = concat( 'beep', 'boop' );
// returns 'beepboop'

str = concat( 'foo', 'bar' );
// returns 'foobar'

str = concat( 'hello', 'world' );
// returns 'helloworld'

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

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

</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/snakecase`][@stdlib/string/base/snakecase]</span><span class="delimiter">: </span><span class="description">convert a string to snake case.</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/snakecase]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/base/snakecase

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

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

</section>

<!-- /.links -->
77 changes: 77 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,77 @@
/**
* @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 = [ 'BEEP', 'FOO', 'HELLO' ];
values2 = [ 'BOOP', 'BAR', 'WORLD' ];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = concat( values1[ i % values1.length ], values2[ i % values2.length ] );

Check warning on line 42 in lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 85. Maximum allowed is 80
if ( typeof out !== '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 = [ 'BEEP', 'FOO', 'HELLO' ];
values2 = [ 'BOOP', 'BAR', 'WORLD' ];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = values1[ i % values1.length ].concat( values2[ i % values2.length ] );

Check warning on line 66 in lib/node_modules/@stdlib/string/base/concat/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 84. Maximum allowed is 80
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( !isString( out ) ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});
23 changes: 23 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,23 @@

{{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}}( 'beep', 'boop' )
'beepboop'

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 out = concat( 'beep', 'boop' );
* // returns 'beepboop'
*/
declare function concat<S1 extends string, S2 extends string>( str1: S1, str2: S2 ): `${S1}${S2}`;


// EXPORTS //

export = concat;
57 changes: 57 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,57 @@
/*
* @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( 'beep', 'boop' ); // $ExpectType "beepboop"
concat( 'foo', 'bar' ); // $ExpectType "foobar"
concat( 'abc' as string, 'xyz' as string ); // $ExpectType string
}

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

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

// The compiler throws an error if the function is provided insufficient arguments...
{
concat( 'beep' ); // $ExpectError
concat(); // $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( 'beep', 'boop' );
console.log( str );
// => 'beepboop'

str = concat( 'foo', 'bar' );
console.log( str );
// => 'foobar'

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

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

str = concat( 'test', '' );
console.log( str );
// => 'test'
40 changes: 40 additions & 0 deletions lib/node_modules/@stdlib/string/base/concat/lib/index.js
Original file line number Diff line number Diff line change
@@ -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( 'beep', 'boop' );
* // returns 'beepboop'
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading