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..e19973dbf6ef --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/README.md @@ -0,0 +1,115 @@ + + +# 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 +``` + +The function properly handles strings containing Unicode grapheme clusters, such as emoji and combining marks. + +```javascript +var bool = isPalindrome( '🍕🔥🍕' ); +// returns true +``` + +
+ + + +
+ +## Examples + +```javascript +var isPalindrome = require( '@stdlib/assert/is-palindrome' ); + +var bool = isPalindrome( 'racecar' ); +// returns true + +bool = isPalindrome( 'ada' ); +// returns true + +bool = isPalindrome( '🍕🔥🍕' ); +// 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..fd29451c3514 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +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) { + 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 (!isBoolean(bool)) { + b.fail('should return a boolean'); + } + b.pass('benchmark finished'); + b.end(); +}); + +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'); + } + } + b.toc(); + if (!isBoolean(bool)) { + b.fail('should return a boolean'); + } + 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..0f874bc58e83 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/repl.txt @@ -0,0 +1,35 @@ + +{{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 + 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}}( '🍕🔥🍕' ) + 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..f042dc19d0ff --- /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: string ): 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..25007fd83bcf --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/docs/types/test.ts @@ -0,0 +1,45 @@ +/** +* @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 + 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 +} 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..a3d514be2985 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/examples/index.js @@ -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. +*/ + +'use strict'; + +var isPalindrome = require( './../lib' ); + +console.log(isPalindrome('racecar')); +// => true + +console.log(isPalindrome('ada')); +// => true + +console.log(isPalindrome('🍕🔥🍕')); +// => 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..e82a503e37bf --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/index.js @@ -0,0 +1,43 @@ +/** +* @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'; + +/** +* Test if a value is a palindrome. +* +* @module @stdlib/assert/is-palindrome +* +* @example +* var isPalindrome = require( '@stdlib/assert/is-palindrome' ); +* +* var bool = isPalindrome( 'racecar' ); +* // returns true +* +* bool = isPalindrome( 'abc' ); +* // returns false +*/ + +// 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..52b5494b6b52 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/lib/main.js @@ -0,0 +1,71 @@ +/** +* @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' ).isPrimitive; +var splitGraphemeClusters = require( '@stdlib/string/split-grapheme-clusters' ); + + +// 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 clusters; + var i; + var j; + + if ( !isString( v ) ) { + return false; + } + clusters = splitGraphemeClusters( v ); + if ( clusters.length <= 1 ) { + return true; + } + + i = 0; + j = clusters.length - 1; + while ( i < j ) { + if ( clusters[ i ] !== clusters[ 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..76b07bccb9b0 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/package.json @@ -0,0 +1,72 @@ +{ + "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", + "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 new file mode 100644 index 000000000000..49522fd3b05d --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-palindrome/test/test.js @@ -0,0 +1,126 @@ +/** +* @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 `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` if a value is not a palindrome', function test(t) { + var values; + var i; + + values = [ + 'abc', + 'stdlib', + 'hello' + ]; + + for (i = 0; i < values.length; i++) { + 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) { + 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(); +}); + +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(); +});