From bbcfe48d4c20a4e6db35474bf9fbbea9c972d316 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Mar 2024 15:02:11 +0000 Subject: [PATCH] Auto-generated commit --- .github/.keepalive | 1 - CONTRIBUTORS | 9 ++ base/stickycase/README.md | 110 +++++++++++++++++++++++++ base/stickycase/benchmark/benchmark.js | 55 +++++++++++++ base/stickycase/docs/repl.txt | 27 ++++++ base/stickycase/docs/types/index.d.ts | 45 ++++++++++ base/stickycase/docs/types/test.ts | 54 ++++++++++++ base/stickycase/examples/index.js | 46 +++++++++++ base/stickycase/lib/index.js | 49 +++++++++++ base/stickycase/lib/main.js | 72 ++++++++++++++++ base/stickycase/package.json | 66 +++++++++++++++ base/stickycase/test/test.js | 51 ++++++++++++ 12 files changed, 584 insertions(+), 1 deletion(-) delete mode 100644 .github/.keepalive create mode 100644 base/stickycase/README.md create mode 100644 base/stickycase/benchmark/benchmark.js create mode 100644 base/stickycase/docs/repl.txt create mode 100644 base/stickycase/docs/types/index.d.ts create mode 100644 base/stickycase/docs/types/test.ts create mode 100644 base/stickycase/examples/index.js create mode 100644 base/stickycase/lib/index.js create mode 100644 base/stickycase/lib/main.js create mode 100644 base/stickycase/package.json create mode 100644 base/stickycase/test/test.js diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e7ca84a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:59:30.932Z diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 6a1c080..8386f88 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,9 +2,11 @@ # # Contributors listed in alphabetical order. +Adarsh Palaskar <83298237+adarshpalaskar1@users.noreply.github.com> Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com> Ali Salesi +Aman Bhansali <92033532+aman-095@users.noreply.github.com> Amit Jimiwal Athan Reines Brendan Graetz @@ -28,6 +30,7 @@ Joris Labie Justin Dennison Karthik Prakash <116057817+skoriop@users.noreply.github.com> Khaldon +Lovelin <100030865+lovelindhoni@users.noreply.github.com> Marcus Fantham Matt Cochrane Mihir Pandit <129577900+MSP20086@users.noreply.github.com> @@ -36,22 +39,28 @@ Momtchil Momtchev Naresh Jagadeesan Nithin Katta <88046362+nithinkatta@users.noreply.github.com> Ognjen Jevremović +Oneday12323 <107678750+Oneday12323@users.noreply.github.com> Philipp Burckhardt Prajwal Kulkarni Pranav Goswami Praneki <97080887+PraneGIT@users.noreply.github.com> Pratik <97464067+Pratik772846@users.noreply.github.com> +Priyansh <88396544+itsspriyansh@users.noreply.github.com> +Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com> Ricky Reusser Robert Gislason Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com> Rutam <138517416+performant23@users.noreply.github.com> Ryan Seal +Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> Seyyed Parsa Neshaei Shraddheya Shendre Shubham Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> Spandan Barve <114365550+marsian83@users.noreply.github.com> Stephannie Jiménez Gacha +Utkarsh <137638507+Ut-the-pro@users.noreply.github.com> Yernar Yergaziyev orimiles5 <97595296+orimiles5@users.noreply.github.com> rei2hu +utkarsh_raj <49344502+rajutkarsh07@users.noreply.github.com> diff --git a/base/stickycase/README.md b/base/stickycase/README.md new file mode 100644 index 0000000..6c4953d --- /dev/null +++ b/base/stickycase/README.md @@ -0,0 +1,110 @@ + + +# stickycase + +> Convert a string to sticky case. + + + +
+ +## 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 +``` + +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 + +str = 'good morning'; +out = stickycase( 'good morning', 0.8 ); +// returns +``` + +
+ + + + + +
+ +## Examples + +```javascript +var stickycase = require( '@stdlib/string/base/stickycase' ); + +var str = 'Hello World!'; +var out = stickycase( str ); +// returns +// returns + +str = 'I am a tiny little teapot'; +out = stickycase( str ); +// returns + +str = 'with big problems'; +out = stickycase( str, 0.1 ); +// returns + +str = 'To be, or not to be: that is the question.'; +out = stickycase( str, 0.9 ); +// returns + +str = 'isMobile'; +out = stickycase( str ); +// returns +``` + +
+ + + + + + + + + + + + + + diff --git a/base/stickycase/benchmark/benchmark.js b/base/stickycase/benchmark/benchmark.js new file mode 100644 index 0000000..d1bc3d2 --- /dev/null +++ b/base/stickycase/benchmark/benchmark.js @@ -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(); +}); diff --git a/base/stickycase/docs/repl.txt b/base/stickycase/docs/repl.txt new file mode 100644 index 0000000..285e7d4 --- /dev/null +++ b/base/stickycase/docs/repl.txt @@ -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!' ) + + + > out = {{alias}}( 'I am a tiny little teapot' ) + + See Also + -------- + diff --git a/base/stickycase/docs/types/index.d.ts b/base/stickycase/docs/types/index.d.ts new file mode 100644 index 0000000..dbba044 --- /dev/null +++ b/base/stickycase/docs/types/index.d.ts @@ -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 + * + * @example + * var str = stickycase( 'hello world', 0.2 ); + * // returns + * + * @example + * var str = stickycase( 'hello world', 0.8 ); + * // returns + */ +declare function stickycase( str: string, p?: number ): string; + + +// EXPORTS // + +export = stickycase; diff --git a/base/stickycase/docs/types/test.ts b/base/stickycase/docs/types/test.ts new file mode 100644 index 0000000..1170791 --- /dev/null +++ b/base/stickycase/docs/types/test.ts @@ -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 +} diff --git a/base/stickycase/examples/index.js b/base/stickycase/examples/index.js new file mode 100644 index 0000000..2feff8b --- /dev/null +++ b/base/stickycase/examples/index.js @@ -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 ); +// => + +str = 'I am a tiny little teapot'; +out = stickycase( str ); +console.log( out ); +// => + +str = 'with big problems'; +out = stickycase( str, 0.1 ); +console.log( out ); +// => + +str = 'To be, or not to be: that is the question.'; +out = stickycase( str, 0.9 ); +console.log( out ); +// => + +str = 'isMobile'; +out = stickycase( str, 0.5 ); +console.log( out ); +// => diff --git a/base/stickycase/lib/index.js b/base/stickycase/lib/index.js new file mode 100644 index 0000000..e387ae7 --- /dev/null +++ b/base/stickycase/lib/index.js @@ -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 +* +* @example +* var stickycase = require( '@stdlib/string/base/stickycase' ); +* var str = stickycase( 'hello world', 0.2 ); +* // returns +* +* @example +* var stickycase = require( '@stdlib/string/base/stickycase' ); +* var str = stickycase( 'hello world', 0.8 ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/base/stickycase/lib/main.js b/base/stickycase/lib/main.js new file mode 100644 index 0000000..fe5c048 --- /dev/null +++ b/base/stickycase/lib/main.js @@ -0,0 +1,72 @@ +/** +* @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 bernoulli = require( '@stdlib/random/base/bernoulli' ); + + +// MAIN // + +/** +* Converts a string to "sticky caps" case. +* +* @param {string} str - input string +* @param {number} [p=0.5] - probability of capitalization (between 0 and 1) +* @returns {string} converted string +* +* @example +* var str = stickycase( 'hello world' ); +* // returns +* +* @example +* var str = stickycase( 'hello world', 0.2 ); +* // returns +* +* @example +* var str = stickycase( 'hello world', 0.8 ); +* // returns +* +* @example +* var str = stickycase( 'hello world', '0.5' ); +* // returns +*/ +function stickycase( str, p ) { + var result = ''; + var char; + var i; + p = ( typeof p === 'number' && p >= 0 && p <= 1 ) ? p : 0.5; + + for ( i = 0; i < str.length; i++ ) { + char = str.charAt( i ); + if ( bernoulli( p ) ) { + char = char.toUpperCase(); + } else { + char = char.toLowerCase(); + } + result += char; + } + return result; +} + + +// EXPORTS // + +module.exports = stickycase; diff --git a/base/stickycase/package.json b/base/stickycase/package.json new file mode 100644 index 0000000..0f50a57 --- /dev/null +++ b/base/stickycase/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/string/base/stickycase", + "version": "0.0.0", + "description": "Convert a string to sticky case.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "base", + "string", + "str", + "case", + "sticky", + "convert" + ], + "__stdlib__": {} +} \ No newline at end of file diff --git a/base/stickycase/test/test.js b/base/stickycase/test/test.js new file mode 100644 index 0000000..c078fa8 --- /dev/null +++ b/base/stickycase/test/test.js @@ -0,0 +1,51 @@ +/** +* @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 tape = require( 'tape' ); +var stickycase = require( './../../../base/stickycase/lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stickycase, 'function', 'main export is a function' ); + t.end(); +}); + +tape('the function converts a string to sticky caps case', function test(t) { + var actual; + + // Test with default probability (p=0.5) + actual = stickycase( 'hello world' ); + t.strictEqual( typeof actual, 'string', 'returns a string' ); + + // Test with lower probability (p=0.2): + actual = stickycase( 'hello world', 0.2 ); + t.strictEqual( typeof actual, 'string', 'returns a string' ); + + // Test with higher probability (p=0.8): + actual = stickycase( 'hello world', 0.8 ); + t.strictEqual( typeof actual, 'string', 'returns a string' ); + + t.end(); +});