Skip to content

Commit

Permalink
feat: add string/base/altcase
Browse files Browse the repository at this point in the history
Closes: #850
PR-URL: 	#1173
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
Jaysukh-409 and kgryte authored Dec 10, 2023
1 parent e49e7ec commit e4cf6a5
Show file tree
Hide file tree
Showing 10 changed files with 688 additions and 0 deletions.
102 changes: 102 additions & 0 deletions lib/node_modules/@stdlib/string/base/altcase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!--
@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.
-->

# altcase

> Convert a string to alternate case.
<!-- Package usage documentation. -->

<section class="usage">

## Usage

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

#### altcase( str )

Converts a string to alternate case.

```javascript
var str = altcase( 'foo bar' );
// returns 'fOo bAr'

str = altcase( 'foo bar baz' );
// returns 'fOo bAr bAz'

str = altcase( 'foo_bar' );
// returns 'fOo_bAr'
```

</section>

<!-- /.usage -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

var str = 'Hello World!';
var out = altcase( str );
// returns 'hElLo wOrLd!'

str = 'I am a tiny little teapot';
out = altcase( str );
// returns 'i aM A TiNy lItTlE TeApOt'

str = 'with big problems';
out = altcase( str );
// returns 'wItH BiG PrObLeMs'

str = 'To be, or not to be: that is the question.';
out = altcase( str );
// returns 'tO Be, Or nOt tO Be: ThAt iS ThE QuEsTiOn.'

str = 'isMobile';
out = altcase( str );
// returns 'iSmObIlE'
```

</section>

<!-- /.examples -->

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

<section class="related">

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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 bench = require( '@stdlib/bench' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var altcase = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var i;

values = [
'beep boop',
'foo bar',
'xyz abc'
];

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

{{alias}}( str )
Converts a string to alternate case.

Parameters
----------
str: string
Input string.

Returns
-------
out: string
Alternate-cased string.

Examples
--------
> var out = {{alias}}( 'Hello World!' )
'hElLo wOrLd!'
> out = {{alias}}( 'I am a tiny little teapot' )
'i aM A TiNy lItTlE TeApOt'

See Also
--------
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/string/base/altcase/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/**
* Converts a string to alternate case.
*
* @param str - string to convert
* @returns alternate-cased string
*
* @example
* var str = altcase( 'beep' );
* // returns 'bEeP'
*
* @example
* var str = altcase( 'beep boop' );
* // returns 'bEeP BoOp'
*
* @example
* var str = altcase( 'Hello World!' );
* // returns 'hElLo wOrLd!'
*/
declare function altcase( str: string ): string;


// EXPORTS //

export = altcase;
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/string/base/altcase/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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.
*/

import altcase = require( './index' );


// TESTS //

// The function returns a string...
{
altcase( 'Hello World!' ); // $ExpectType string
}

// The compiler throws an error if the function is provided a value other than a string...
{
altcase( true ); // $ExpectError
altcase( false ); // $ExpectError
altcase( null ); // $ExpectError
altcase( undefined ); // $ExpectError
altcase( 5 ); // $ExpectError
altcase( [] ); // $ExpectError
altcase( {} ); // $ExpectError
altcase( ( x: number ): number => x ); // $ExpectError
}

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

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

var str = 'Hello World!';
var out = altcase( str );
console.log( out );
// => 'hElLo wOrLd!'

str = 'I am a tiny little teapot';
out = altcase( str );
console.log( out );
// => 'i aM A TiNy lItTlE TeApOt'

str = 'with big problems';
out = altcase( str );
console.log( out );
// => 'wItH BiG PrObLeMs'

str = 'To be, or not to be: that is the question.';
out = altcase( str );
console.log( out );
// => 'tO Be, Or nOt tO Be: ThAt iS ThE QuEsTiOn.'

str = 'isMobile';
out = altcase( str );
console.log( out );
// => 'iSmObIlE'
47 changes: 47 additions & 0 deletions lib/node_modules/@stdlib/string/base/altcase/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @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';

/**
* Convert a string to alternate case.
*
* @module @stdlib/string/base/altcase
*
* @example
* var altcase = require( '@stdlib/string/base/altcase' );
*
* var str = altcase( 'aBcDeF' );
* // returns 'aBcDeF'
*
* str = altcase( 'Hello World!' );
* // returns 'hElLo wOrLd!'
*
* str = altcase( 'I am a robot' );
* // returns 'i aM A RoBoT'
*/


// MODULES //

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


// EXPORTS //

module.exports = main;
Loading

1 comment on commit e4cf6a5

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
string/base/altcase $\color{green}115/115$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}115/115$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.