UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

24 lines (23 loc) 1.04 kB
import { _phpCastString } from "../_helpers/_phpCastString.js"; import { strnatcmp } from "../strings/strnatcmp.js"; export function strnatcasecmp(...providedArgs) { // discuss at: https://locutus.io/php/strnatcasecmp/ // parity verified: PHP 8.3 // original by: Martin Pool // reimplemented by: Pierre-Luc Paour // reimplemented by: Kristof Coomans (SCK-CEN (Belgian Nucleair Research Centre)) // reimplemented by: Brett Zamir (https://brett-zamir.me) // bugfixed by: Kevin van Zonneveld (https://kvz.io) // input by: Devan Penner-Woelk // improved by: Kevin van Zonneveld (https://kvz.io) // reimplemented by: Rafał Kukawski // example 1: strnatcasecmp(10, 1) // returns 1: 1 // example 2: strnatcasecmp('1', '10') // returns 2: -1 if (providedArgs.length !== 2) { return null; } const [a, b] = providedArgs; return strnatcmp(_phpCastString(a).toLowerCase(), _phpCastString(b).toLowerCase()); }