From 80644447bb567ea998848e7bb107b602a25a017b Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Sun, 25 Jan 2026 01:12:41 +0530 Subject: [PATCH 1/3] feat: add assert/is-palindrome --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/assert/is-palindrome/README.md | 105 ++++++++++++++++++ .../is-palindrome/benchmark/benchmark.js | 69 ++++++++++++ .../assert/is-palindrome/docs/repl.txt | 30 +++++ .../is-palindrome/docs/types/index.d.ts | 36 ++++++ .../assert/is-palindrome/docs/types/test.ts | 34 ++++++ .../assert/is-palindrome/examples/index.js | 33 ++++++ .../@stdlib/assert/is-palindrome/lib/index.js | 40 +++++++ .../@stdlib/assert/is-palindrome/lib/main.js | 70 ++++++++++++ .../@stdlib/assert/is-palindrome/package.json | 70 ++++++++++++ .../@stdlib/assert/is-palindrome/test/test.js | 73 ++++++++++++ 10 files changed, 560 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/README.md create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/package.json create mode 100644 lib/node_modules/@stdlib/assert/is-palindrome/test/test.js diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/README.md b/lib/node_modules/@stdlib/assert/is-palindrome/README.md new file mode 100644 index 000000000000..ecc714142a6b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/README.md @@ -0,0 +1,105 @@ + + +# isPalindrome + +> Test if a value is a palindrome. + +
+ +## Usage + +```javascript +var isPalindrome = require( '@stdlib/assert/is-palindrome' ); +``` + +#### isPalindrome( value ) + +Tests if a `value` is a palindrome `string`. + +```javascript +var bool = isPalindrome( 'racecar' ); +// returns true + +bool = isPalindrome( 'level' ); +// returns true + +bool = isPalindrome( 'abc' ); +// returns false + +bool = isPalindrome( null ); +// returns false +``` + +
+ + + +
+ +## Examples + +```javascript +var isPalindrome = require( '@stdlib/assert/is-palindrome' ); + +var bool = isPalindrome( 'racecar' ); +// returns true + +bool = isPalindrome( 'ada' ); +// returns true + +bool = isPalindrome( 'website' ); +// returns false + +bool = isPalindrome( null ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js new file mode 100644 index 000000000000..1b02617a8458 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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' ); +var pkg = require( './../package.json' ).name; +var isPalindrome = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isPalindrome( 'racecar' ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isString( pkg ) ) { + b.fail( 'should be a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg + ':long_string', function benchmark( b ) { + var bool; + var str; + var i; + + str = 'tattarrattat'; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isPalindrome( str ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !bool ) { + b.fail( 'should return true' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt new file mode 100644 index 000000000000..fe8876b38725 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}( value ) + Tests if a value is a palindrome. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating if a value is a palindrome. + + Examples + -------- + > var bool = {{alias}}( 'racecar' ) + true + > bool = {{alias}}( 'level' ) + true + > bool = {{alias}}( 'noon' ) + true + > bool = {{alias}}( 'stdlib' ) + false + > bool = {{alias}}( null ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts new file mode 100644 index 000000000000..9c5907f04448 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 + +/** +* Tests if a value is a palindrome. +* +* @param v - value to test +* @returns boolean indicating if a value is a palindrome +* +* @example +* var bool = isPalindrome( 'racecar' ); +* // returns true +*/ +declare function isPalindrome( v: any ): boolean; + + +// EXPORTS // + +export = isPalindrome; diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts new file mode 100644 index 000000000000..2c434ad5ae82 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isPalindrome = require( '@stdlib/assert/is-palindrome' ); + + +// TESTS // + +// The function returns a boolean... +{ + isPalindrome( 'racecar' ); // $ExpectType boolean + isPalindrome( '' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + isPalindrome(); // $ExpectError + isPalindrome( 'racecar', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js b/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js new file mode 100644 index 000000000000..16bb3e1a7976 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isPalindrome = require( './../lib' ); + +console.log( isPalindrome( 'racecar' ) ); +// => true + +console.log( isPalindrome( 'ada' ) ); +// => true + +console.log( isPalindrome( 'website' ) ); +// => false + +console.log( isPalindrome( null ) ); +// => false diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js b/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js new file mode 100644 index 000000000000..a5f87d0a244b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Assert if a value is a palindrome. +* +* @module @stdlib/assert/is-palindrome +* +* @example +* var isPalindrome = require( '@stdlib/assert/is-palindrome' ); +* +* var bool = isPalindrome( 'level' ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js new file mode 100644 index 000000000000..d8efc047939d --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isString = require( '@stdlib/assert/is-string' ); + + +// MAIN // + +/** +* Tests if a value is a palindrome. +* +* @param {*} v - value to test +* @returns {boolean} boolean indicating if a value is a palindrome +* +* @example +* var bool = isPalindrome( 'racecar' ); +* // returns true +* +* @example +* var bool = isPalindrome( 'abc' ); +* // returns false +*/ +function isPalindrome( v ) { + var len; + var i; + var j; + + if ( !isString( v ) ) { + return false; + } + len = v.length; + if ( len <= 1 ) { + return true; + } + + i = 0; + j = len - 1; + while ( i < j ) { + if ( v.charAt( i ) !== v.charAt( j ) ) { + return false; + } + i += 1; + j -= 1; + } + return true; +} + + +// EXPORTS // + +module.exports = isPalindrome; diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/package.json b/lib/node_modules/@stdlib/assert/is-palindrome/package.json new file mode 100644 index 000000000000..99d780be4e6a --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/assert/is-palindrome", + "version": "0.0.0", + "description": "Test if a value is a palindrome.", + "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", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "string", + "palindrome", + "is", + "ispalindrome", + "type", + "check", + "validate", + "valid", + "test" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js new file mode 100644 index 000000000000..c9815738f4f4 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isPalindrome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isPalindrome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns true if a value is a palindrome', function test( t ) { + var values; + var i; + + values = [ + 'racecar', + 'level', + 'a', + '', + 'step on no pets', + 'deleveled' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isPalindrome( values[ i ] ), true, 'returns true for ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns false if a value is not a palindrome', function test( t ) { + var values; + var i; + + values = [ + 'abc', + 'stdlib', + null, + undefined, + 121, + NaN, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isPalindrome( values[ i ] ), false, 'returns false for ' + values[ i ] ); + } + t.end(); +}); From 66ac84590dc760bde1f415f65001ef9026ccd54c Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Fri, 13 Feb 2026 02:34:28 +0530 Subject: [PATCH 2/3] fix: handle Unicode grapheme clusters and add related tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/assert/is-palindrome/lib/main.js | 17 +++--- .../@stdlib/assert/is-palindrome/test/test.js | 53 +++++++++++++++---- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js index d8efc047939d..b75ff16375c2 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js @@ -21,6 +21,7 @@ // MODULES // var isString = require( '@stdlib/assert/is-string' ); +var splitGraphemeClusters = require( '@stdlib/string/split-grapheme-clusters' ); // MAIN // @@ -39,23 +40,23 @@ var isString = require( '@stdlib/assert/is-string' ); * var bool = isPalindrome( 'abc' ); * // returns false */ -function isPalindrome( v ) { - var len; +function isPalindrome(v) { + var clusters; var i; var j; - if ( !isString( v ) ) { + if (!isString(v)) { return false; } - len = v.length; - if ( len <= 1 ) { + clusters = splitGraphemeClusters(v); + if (clusters.length <= 1) { return true; } i = 0; - j = len - 1; - while ( i < j ) { - if ( v.charAt( i ) !== v.charAt( j ) ) { + j = clusters.length - 1; + while (i < j) { + if (clusters[i] !== clusters[j]) { return false; } i += 1; diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js index c9815738f4f4..d5761ddc66f1 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js @@ -26,13 +26,13 @@ var isPalindrome = require( './../lib' ); // TESTS // -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof isPalindrome, 'function', 'main export is a function' ); +tape('main export is a function', function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof isPalindrome, 'function', 'main export is a function'); t.end(); }); -tape( 'the function returns true if a value is a palindrome', function test( t ) { +tape('the function returns true if a value is a palindrome', function test(t) { var values; var i; @@ -45,13 +45,13 @@ tape( 'the function returns true if a value is a palindrome', function test( t ) 'deleveled' ]; - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( isPalindrome( values[ i ] ), true, 'returns true for ' + values[ i ] ); + for (i = 0; i < values.length; i++) { + t.strictEqual(isPalindrome(values[i]), true, 'returns true for ' + values[i]); } t.end(); }); -tape( 'the function returns false if a value is not a palindrome', function test( t ) { +tape('the function returns false if a value is not a palindrome', function test(t) { var values; var i; @@ -66,8 +66,43 @@ tape( 'the function returns false if a value is not a palindrome', function test [] ]; - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( isPalindrome( values[ i ] ), false, 'returns false for ' + values[ i ] ); + for (i = 0; i < values.length; i++) { + t.strictEqual(isPalindrome(values[i]), false, 'returns false for ' + values[i]); + } + t.end(); +}); + +tape('the function returns true for palindromes containing Unicode grapheme clusters', function test(t) { + var values; + var i; + + values = [ + '🍕🔥🍕', + '🍕🍕', + '😀😁😀', + '🇫🇷🇫🇷', + 'café\u0301fac', + 'a\u0308a\u0308' + ]; + + for (i = 0; i < values.length; i++) { + t.strictEqual(isPalindrome(values[i]), true, 'returns true for Unicode palindrome'); + } + t.end(); +}); + +tape('the function returns false for non-palindromes containing Unicode grapheme clusters', function test(t) { + var values; + var i; + + values = [ + '🍕🔥', + '😀😁', + '🍕🔥🍕🔥' + ]; + + for (i = 0; i < values.length; i++) { + t.strictEqual(isPalindrome(values[i]), false, 'returns false for Unicode non-palindrome'); } t.end(); }); From efb164e8653de7fa146faefbe8ba5ac0712e55f7 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Mon, 2 Mar 2026 22:37:18 +0530 Subject: [PATCH 3/3] chore: update is-palindrome to strictly validates string input and correctly handles Unicode grapheme clusters --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/assert/is-palindrome/README.md | 10 ++++ .../is-palindrome/benchmark/benchmark.js | 35 +++++------ .../assert/is-palindrome/docs/repl.txt | 5 ++ .../is-palindrome/docs/types/index.d.ts | 2 +- .../assert/is-palindrome/docs/types/test.ts | 15 ++++- .../assert/is-palindrome/examples/index.js | 11 ++-- .../@stdlib/assert/is-palindrome/lib/index.js | 7 ++- .../@stdlib/assert/is-palindrome/lib/main.js | 14 ++--- .../@stdlib/assert/is-palindrome/package.json | 4 +- .../@stdlib/assert/is-palindrome/test/test.js | 58 ++++++++++++------- 10 files changed, 107 insertions(+), 54 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/README.md b/lib/node_modules/@stdlib/assert/is-palindrome/README.md index ecc714142a6b..e19973dbf6ef 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/README.md +++ b/lib/node_modules/@stdlib/assert/is-palindrome/README.md @@ -48,6 +48,13 @@ bool = isPalindrome( null ); // returns false ``` +The function properly handles strings containing Unicode grapheme clusters, such as emoji and combining marks. + +```javascript +var bool = isPalindrome( '🍕🔥🍕' ); +// returns true +``` + @@ -65,6 +72,9 @@ var bool = isPalindrome( 'racecar' ); bool = isPalindrome( 'ada' ); // returns true +bool = isPalindrome( '🍕🔥🍕' ); +// returns true + bool = isPalindrome( 'website' ); // returns false diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js index 1b02617a8458..fd29451c3514 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.js @@ -21,49 +21,50 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isString = require( '@stdlib/assert/is-string' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var isPalindrome = require( './../lib' ); // MAIN // -bench( pkg, function benchmark( b ) { +bench(pkg, function benchmark(b) { var bool; var i; b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = isPalindrome( 'racecar' ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); + for (i = 0; i < b.iterations; i++) { + bool = isPalindrome('racecar'); + if (typeof bool !== 'boolean') { + b.fail('should return a boolean'); } } b.toc(); - if ( !isString( pkg ) ) { - b.fail( 'should be a string' ); + if (!isBoolean(bool)) { + b.fail('should return a boolean'); } - b.pass( 'benchmark finished' ); + b.pass('benchmark finished'); b.end(); }); -bench( pkg + ':long_string', function benchmark( b ) { +bench(format('%s::long_string', pkg), function benchmark(b) { var bool; var str; var i; str = 'tattarrattat'; b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = isPalindrome( str ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); + for (i = 0; i < b.iterations; i++) { + bool = isPalindrome(str); + if (typeof bool !== 'boolean') { + b.fail('should return a boolean'); } } b.toc(); - if ( !bool ) { - b.fail( 'should return true' ); + if (!isBoolean(bool)) { + b.fail('should return a boolean'); } - b.pass( 'benchmark finished' ); + b.pass('benchmark finished'); b.end(); }); diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt index fe8876b38725..0f874bc58e83 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt @@ -2,6 +2,9 @@ {{alias}}( value ) Tests if a value is a palindrome. + The function properly handles strings containing Unicode grapheme + clusters, such as emoji and combining marks. + Parameters ---------- value: any @@ -20,6 +23,8 @@ true > bool = {{alias}}( 'noon' ) true + > bool = {{alias}}( '🍕🔥🍕' ) + true > bool = {{alias}}( 'stdlib' ) false > bool = {{alias}}( null ) diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts index 9c5907f04448..f042dc19d0ff 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/index.d.ts @@ -28,7 +28,7 @@ * var bool = isPalindrome( 'racecar' ); * // returns true */ -declare function isPalindrome( v: any ): boolean; +declare function isPalindrome( v: string ): boolean; // EXPORTS // diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts index 2c434ad5ae82..25007fd83bcf 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts @@ -25,10 +25,21 @@ import isPalindrome = require( '@stdlib/assert/is-palindrome' ); { isPalindrome( 'racecar' ); // $ExpectType boolean isPalindrome( '' ); // $ExpectType boolean + isPalindrome( '🍕🔥🍕' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a value other than a string... +{ + isPalindrome( true ) ; // $ExpectError + isPalindrome( false ); // $ExpectError + isPalindrome( 123 ); // $ExpectError + isPalindrome( [] ); // $ExpectError + isPalindrome( {} ); // $ExpectError + isPalindrome( null ); // $ExpectError } // The compiler throws an error if the function is provided an invalid number of arguments... { - isPalindrome(); // $ExpectError - isPalindrome( 'racecar', {} ); // $ExpectError + isPalindrome( ); // $ExpectError + isPalindrome( 'racecar' , {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js b/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js index 16bb3e1a7976..a3d514be2985 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js @@ -20,14 +20,17 @@ var isPalindrome = require( './../lib' ); -console.log( isPalindrome( 'racecar' ) ); +console.log(isPalindrome('racecar')); // => true -console.log( isPalindrome( 'ada' ) ); +console.log(isPalindrome('ada')); // => true -console.log( isPalindrome( 'website' ) ); +console.log(isPalindrome('🍕🔥🍕')); +// => true + +console.log(isPalindrome('website')); // => false -console.log( isPalindrome( null ) ); +console.log(isPalindrome(null)); // => false diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js b/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js index a5f87d0a244b..e82a503e37bf 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js @@ -19,15 +19,18 @@ 'use strict'; /** -* Assert if a value is a palindrome. +* Test if a value is a palindrome. * * @module @stdlib/assert/is-palindrome * * @example * var isPalindrome = require( '@stdlib/assert/is-palindrome' ); * -* var bool = isPalindrome( 'level' ); +* var bool = isPalindrome( 'racecar' ); * // returns true +* +* bool = isPalindrome( 'abc' ); +* // returns false */ // MODULES // diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js index b75ff16375c2..52b5494b6b52 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var isString = require( '@stdlib/assert/is-string' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var splitGraphemeClusters = require( '@stdlib/string/split-grapheme-clusters' ); @@ -40,23 +40,23 @@ var splitGraphemeClusters = require( '@stdlib/string/split-grapheme-clusters' ); * var bool = isPalindrome( 'abc' ); * // returns false */ -function isPalindrome(v) { +function isPalindrome( v ) { var clusters; var i; var j; - if (!isString(v)) { + if ( !isString( v ) ) { return false; } - clusters = splitGraphemeClusters(v); - if (clusters.length <= 1) { + clusters = splitGraphemeClusters( v ); + if ( clusters.length <= 1 ) { return true; } i = 0; j = clusters.length - 1; - while (i < j) { - if (clusters[i] !== clusters[j]) { + while ( i < j ) { + if ( clusters[ i ] !== clusters[ j ] ) { return false; } i += 1; diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/package.json b/lib/node_modules/@stdlib/assert/is-palindrome/package.json index 99d780be4e6a..76b07bccb9b0 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/package.json +++ b/lib/node_modules/@stdlib/assert/is-palindrome/package.json @@ -65,6 +65,8 @@ "check", "validate", "valid", - "test" + "test", + "unicode", + "grapheme" ] } diff --git a/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js index d5761ddc66f1..49522fd3b05d 100644 --- a/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js +++ b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js @@ -32,7 +32,7 @@ tape('main export is a function', function test(t) { t.end(); }); -tape('the function returns true if a value is a palindrome', function test(t) { +tape('the function returns `true` if a value is a palindrome', function test(t) { var values; var i; @@ -51,47 +51,42 @@ tape('the function returns true if a value is a palindrome', function test(t) { t.end(); }); -tape('the function returns false if a value is not a palindrome', function test(t) { +tape('the function returns `true` for palindromes containing Unicode grapheme clusters', function test(t) { var values; var i; values = [ - 'abc', - 'stdlib', - null, - undefined, - 121, - NaN, - {}, - [] + '🍕🔥🍕', + '🍕🍕', + '😀😁😀', + '🇫🇷🇫🇷', + 'café\u0301fac', + 'a\u0308a\u0308' ]; for (i = 0; i < values.length; i++) { - t.strictEqual(isPalindrome(values[i]), false, 'returns false for ' + values[i]); + t.strictEqual(isPalindrome(values[i]), true, 'returns true for Unicode palindrome'); } t.end(); }); -tape('the function returns true for palindromes containing Unicode grapheme clusters', function test(t) { +tape('the function returns `false` if a value is not a palindrome', function test(t) { var values; var i; values = [ - '🍕🔥🍕', - '🍕🍕', - '😀😁😀', - '🇫🇷🇫🇷', - 'café\u0301fac', - 'a\u0308a\u0308' + 'abc', + 'stdlib', + 'hello' ]; for (i = 0; i < values.length; i++) { - t.strictEqual(isPalindrome(values[i]), true, 'returns true for Unicode palindrome'); + t.strictEqual(isPalindrome(values[i]), false, 'returns false for ' + values[i]); } t.end(); }); -tape('the function returns false for non-palindromes containing Unicode grapheme clusters', function test(t) { +tape('the function returns `false` for non-palindromes containing Unicode grapheme clusters', function test(t) { var values; var i; @@ -106,3 +101,26 @@ tape('the function returns false for non-palindromes containing Unicode grapheme } t.end(); }); + +tape('the function returns `false` if not provided a string', function test(t) { + var values; + var i; + + values = [ + void 0, + null, + 0, + 121, + NaN, + false, + true, + [], + {}, + function noop() { } + ]; + + for (i = 0; i < values.length; i++) { + t.strictEqual(isPalindrome(values[i]), false, 'returns false when provided ' + values[i]); + } + t.end(); +});