-
-
Notifications
You must be signed in to change notification settings - Fork 836
feat: add string/base/stickycase
#1447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4cab156
feat(string): implement stickycase
anudeeps0306 37e746e
fix: correct JavaScript example in README.md
anudeeps0306 b8e84a7
chore: update copyright years
stdlib-bot c2ed871
Update lib/node_modules/@stdlib/string/base/stickycase/README.md
anudeeps0306 a1c0dfb
Update lib/node_modules/@stdlib/string/base/stickycase/README.md
anudeeps0306 d9aad63
Update lib/node_modules/@stdlib/string/base/stickycase/docs/repl.txt
anudeeps0306 74de902
Update lib/node_modules/@stdlib/string/base/stickycase/docs/repl.txt
anudeeps0306 8b40e50
Update lib/node_modules/@stdlib/string/base/stickycase/docs/repl.txt
anudeeps0306 8b21dc2
Update lib/node_modules/@stdlib/string/base/stickycase/docs/repl.txt
anudeeps0306 ae888a0
Update lib/node_modules/@stdlib/string/base/stickycase/docs/types/ind…
anudeeps0306 379a186
Update lib/node_modules/@stdlib/string/base/stickycase/docs/types/tes…
anudeeps0306 0583e00
Update lib/node_modules/@stdlib/string/base/stickycase/test/test.js
anudeeps0306 d92a91e
Update lib/node_modules/@stdlib/string/base/stickycase/lib/main.js
anudeeps0306 842f85c
Update lib/node_modules/@stdlib/string/base/stickycase/lib/main.js
anudeeps0306 98ffb43
Update lib/node_modules/@stdlib/string/base/stickycase/docs/types/ind…
anudeeps0306 7d61c0d
Update lib/node_modules/@stdlib/string/base/stickycase/docs/types/ind…
anudeeps0306 5410b18
Update lib/node_modules/@stdlib/string/base/stickycase/docs/types/tes…
anudeeps0306 0344954
Update lib/node_modules/@stdlib/string/base/stickycase/examples/index.js
anudeeps0306 d2f97c5
Update lib/node_modules/@stdlib/string/base/stickycase/README.md
anudeeps0306 d820594
Update lib/node_modules/@stdlib/string/base/stickycase/lib/index.js
anudeeps0306 24bcb87
Update lib/node_modules/@stdlib/string/base/stickycase/package.json
anudeeps0306 0437efb
Update lib/node_modules/@stdlib/string/base/stickycase/package.json
anudeeps0306 03b65c4
Update test.ts
anudeeps0306 22d647e
Update lib/node_modules/@stdlib/string/base/stickycase/test/test.js
Planeshifter 70674ae
Update lib/node_modules/@stdlib/string/base/stickycase/README.md
Planeshifter c6fab68
Update lib/node_modules/@stdlib/string/base/stickycase/README.md
Planeshifter 56006e2
Update lib/node_modules/@stdlib/string/base/stickycase/README.md
Planeshifter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
lib/node_modules/@stdlib/string/base/stickycase/README.md
This file contains hidden or 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 --> |
55 changes: 55 additions & 0 deletions
55
lib/node_modules/@stdlib/string/base/stickycase/benchmark/benchmark.js
This file contains hidden or 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( '@stdlib/string/base/stickycase/package.json' ).name; | ||
var stickycase = require( '@stdlib/string/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(); | ||
}); |
27 changes: 27 additions & 0 deletions
27
lib/node_modules/@stdlib/string/base/stickycase/docs/repl.txt
This file contains hidden or 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 | ||
-------- | ||
|
45 changes: 45 additions & 0 deletions
45
lib/node_modules/@stdlib/string/base/stickycase/docs/types/index.d.ts
This file contains hidden or 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; |
54 changes: 54 additions & 0 deletions
54
lib/node_modules/@stdlib/string/base/stickycase/docs/types/test.ts
This file contains hidden or 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 | ||
} | ||
|
||
anudeeps0306 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 | ||
} |
46 changes: 46 additions & 0 deletions
46
lib/node_modules/@stdlib/string/base/stickycase/examples/index.js
This file contains hidden or 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> |
49 changes: 49 additions & 0 deletions
49
lib/node_modules/@stdlib/string/base/stickycase/lib/index.js
This file contains hidden or 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,49 @@ | ||
/** | ||
* @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'; | ||
|
||
/** | ||
* Convert a string to "sticky caps" case. | ||
* | ||
* @module @stdlib/string/base/stickycase | ||
* | ||
* @example | ||
* var stickycase = require( '@stdlib/string/base/stickycase' ); | ||
* var str = stickycase( 'hello world' ); | ||
* // returns <string> | ||
* | ||
* @example | ||
* var stickycase = require( '@stdlib/string/base/stickycase' ); | ||
* var str = stickycase( 'hello world', 0.2 ); | ||
* // returns <string> | ||
* | ||
* @example | ||
* var stickycase = require( '@stdlib/string/base/stickycase' ); | ||
* var str = stickycase( 'hello world', 0.8 ); | ||
* // returns <string> | ||
*/ | ||
|
||
// MODULES // | ||
|
||
var main = require( './main.js' ); | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = main; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.