UNPKG

@c_s_v_s_subrahmanyam/string-utils

Version:

A comprehensive utility library for advanced string operations.

15 lines (13 loc) 510 B
// Partitioning utilities module.exports = { partition: (str, delimiter) => { const index = str.indexOf(delimiter); if (index === -1) return [str, '', '']; return [str.slice(0, index), delimiter, str.slice(index + delimiter.length)]; }, rpartition: (str, delimiter) => { const index = str.lastIndexOf(delimiter); if (index === -1) return [str, '', '']; return [str.slice(0, index), delimiter, str.slice(index + delimiter.length)]; }, };