-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee63f54
commit bbcfe48
Showing
12 changed files
with
584 additions
and
1 deletion.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
# | ||
# Contributors listed in alphabetical order. | ||
|
||
Adarsh Palaskar <[email protected]> | ||
Aditya Sapra <[email protected]> | ||
AgPriyanshu18 <[email protected]> | ||
Ali Salesi <[email protected]> | ||
Aman Bhansali <[email protected]> | ||
Amit Jimiwal <[email protected]> | ||
Athan Reines <[email protected]> | ||
Brendan Graetz <[email protected]> | ||
|
@@ -28,6 +30,7 @@ Joris Labie <[email protected]> | |
Justin Dennison <[email protected]> | ||
Karthik Prakash <[email protected]> | ||
Khaldon <[email protected]> | ||
Lovelin <[email protected]> | ||
Marcus Fantham <[email protected]> | ||
Matt Cochrane <[email protected]> | ||
Mihir Pandit <[email protected]> | ||
|
@@ -36,22 +39,28 @@ Momtchil Momtchev <[email protected]> | |
Naresh Jagadeesan <[email protected]> | ||
Nithin Katta <[email protected]> | ||
Ognjen Jevremović <[email protected]> | ||
Oneday12323 <[email protected]> | ||
Philipp Burckhardt <[email protected]> | ||
Prajwal Kulkarni <[email protected]> | ||
Pranav Goswami <[email protected]> | ||
Praneki <[email protected]> | ||
Pratik <[email protected]> | ||
Priyansh <[email protected]> | ||
Rejoan Sardar <[email protected]> | ||
Ricky Reusser <[email protected]> | ||
Robert Gislason <[email protected]> | ||
Roman Stetsyk <[email protected]> | ||
Rutam <[email protected]> | ||
Ryan Seal <[email protected]> | ||
Sai Srikar Dumpeti <[email protected]> | ||
Seyyed Parsa Neshaei <[email protected]> | ||
Shraddheya Shendre <[email protected]> | ||
Shubham <[email protected]> | ||
Snehil Shah <[email protected]> | ||
Spandan Barve <[email protected]> | ||
Stephannie Jiménez Gacha <[email protected]> | ||
Utkarsh <[email protected]> | ||
Yernar Yergaziyev <[email protected]> | ||
orimiles5 <[email protected]> | ||
rei2hu <[email protected]> | ||
utkarsh_raj <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<!-- | ||
@license Apache-2.0 | ||
Copyright (c) 2024 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. | ||
--> | ||
|
||
# stickycase | ||
|
||
> Convert a string to sticky case. | ||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var stickycase = require( '@stdlib/string/base/stickycase' ); | ||
``` | ||
|
||
#### stickycase( str\[, p] ) | ||
|
||
Converts a string to sticky case, where each character in the input string is randomly converted to either uppercase or lowercase. | ||
|
||
```javascript | ||
var str = 'hello world'; | ||
var out = stickycase( 'hello world' ); | ||
// returns <string> | ||
``` | ||
|
||
By default, the probability for any character to be capitalized is `0.5`. To set a different probability, provide a `p` argument. | ||
|
||
```javascript | ||
var str = 'welcome!'; | ||
var out = stickycase( 'welcome!', 0.2 ); | ||
// returns <string> | ||
|
||
str = 'good morning'; | ||
out = stickycase( 'good morning', 0.8 ); | ||
// returns <string> | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
```javascript | ||
var stickycase = require( '@stdlib/string/base/stickycase' ); | ||
|
||
var str = 'Hello World!'; | ||
var out = stickycase( str ); | ||
// returns <string> | ||
// returns <string> | ||
|
||
str = 'I am a tiny little teapot'; | ||
out = stickycase( str ); | ||
// returns <string> | ||
|
||
str = 'with big problems'; | ||
out = stickycase( str, 0.1 ); | ||
// returns <string> | ||
|
||
str = 'To be, or not to be: that is the question.'; | ||
out = stickycase( str, 0.9 ); | ||
// returns <string> | ||
|
||
str = 'isMobile'; | ||
out = stickycase( str ); | ||
// returns <string> | ||
``` | ||
|
||
</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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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( './../../../base/stickycase/package.json' ).name; | ||
var stickycase = require( './../../../base/stickycase/lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var values; | ||
var out; | ||
var i; | ||
|
||
values = [ | ||
'hello world', | ||
'lorem ipsum dolor sit amet', | ||
'quick brown fox jumps over the lazy dog' | ||
]; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = stickycase( 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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
{{alias}}( str[, p] ) | ||
Converts a string to sticky case. | ||
|
||
Parameters | ||
---------- | ||
str: string | ||
Input string. | ||
|
||
p: number | ||
Probability of capitalization. | ||
|
||
Returns | ||
------- | ||
out: string | ||
Sticky-cased string. | ||
|
||
Examples | ||
-------- | ||
> var out = {{alias}}( 'Hello World!' ) | ||
<string> | ||
|
||
> out = {{alias}}( 'I am a tiny little teapot' ) | ||
<string> | ||
See Also | ||
-------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 "sticky caps" case. | ||
* | ||
* @param str - input string | ||
* @param p - probability of capitalization (default: 0.5) | ||
* @returns sticky case string | ||
* | ||
* @example | ||
* var str = stickycase( 'hello world' ); | ||
* // returns <string> | ||
* | ||
* @example | ||
* var str = stickycase( 'hello world', 0.2 ); | ||
* // returns <string> | ||
* | ||
* @example | ||
* var str = stickycase( 'hello world', 0.8 ); | ||
* // returns <string> | ||
*/ | ||
declare function stickycase( str: string, p?: number ): string; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = stickycase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 stickycase from './index'; | ||
|
||
// TESTS // | ||
|
||
// The function returns a string... | ||
{ | ||
stickycase( 'hello world' ); // $ExpectType string | ||
stickycase( 'hello world', 0.3 ); // $ExpectType string | ||
} | ||
|
||
// The compiler throws an error if the function is provided a value other than a string... | ||
{ | ||
stickycase( true ); // $ExpectError | ||
stickycase( false ); // $ExpectError | ||
stickycase( undefined ); // $ExpectError | ||
stickycase( 5 ); // $ExpectError | ||
stickycase( [] ); // $ExpectError | ||
stickycase( {} ); // $ExpectError | ||
stickycase( ( x: number ): number => x ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the second parameter is not a number... | ||
{ | ||
stickycase('hello world', true); // $ExpectError | ||
stickycase('hello world', false); // $ExpectError | ||
stickycase('hello world', undefined); // $ExpectError | ||
stickycase('hello world', 'test'); // $ExpectError | ||
stickycase('hello world', []); // $ExpectError | ||
stickycase('hello world', {}); // $ExpectError | ||
stickycase('hello world', (x: number): number => x); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided insufficient arguments... | ||
{ | ||
stickycase(); // $ExpectError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 stickycase = require( './../lib' ); | ||
|
||
var str = 'Hello World!'; | ||
var out = stickycase( str ); | ||
console.log( out ); | ||
// => <string> | ||
|
||
str = 'I am a tiny little teapot'; | ||
out = stickycase( str ); | ||
console.log( out ); | ||
// => <string> | ||
|
||
str = 'with big problems'; | ||
out = stickycase( str, 0.1 ); | ||
console.log( out ); | ||
// => <string> | ||
|
||
str = 'To be, or not to be: that is the question.'; | ||
out = stickycase( str, 0.9 ); | ||
console.log( out ); | ||
// => <string> | ||
|
||
str = 'isMobile'; | ||
out = stickycase( str, 0.5 ); | ||
console.log( out ); | ||
// => <string> |
Oops, something went wrong.