UNPKG

locutus

Version:

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

18 lines (17 loc) 613 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HasPrefix = HasPrefix; function HasPrefix(s, prefix) { // discuss at: https://locutus.io/golang/strings/HasPrefix // parity verified: Go 1.23 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: HasPrefix('Gopher', 'Go') // returns 1: true // example 2: HasPrefix('Gopher', 'C') // returns 2: false // example 3: HasPrefix('Gopher', '') // returns 3: true s = s + ''; prefix = prefix + ''; return s.startsWith(prefix); }