locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
17 lines (16 loc) • 740 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.delete_prefix = delete_prefix;
function delete_prefix(str, prefix) {
// parity verified: Ruby 3.3
// discuss at: https://locutus.io/ruby/String/delete_prefix/
// original by: Kevin van Zonneveld (https://kvz.io)
// note 1: Removes prefix when present and otherwise returns the original string unchanged.
// example 1: delete_prefix('prefix-value', 'prefix-')
// returns 1: 'value'
// example 2: delete_prefix('value', 'x')
// returns 2: 'value'
const input = str + '';
const needle = prefix + '';
return input.startsWith(needle) ? input.slice(needle.length) : input;
}