IsStringPrefix.js 463 B

12345678910111213141516171819
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var StringIndexOf = require('./StringIndexOf');
  4. // https://262.ecma-international.org/13.0/#sec-isstringprefix
  5. module.exports = function IsStringPrefix(p, q) {
  6. if (typeof p !== 'string') {
  7. throw new $TypeError('Assertion failed: "p" must be a String');
  8. }
  9. if (typeof q !== 'string') {
  10. throw new $TypeError('Assertion failed: "q" must be a String');
  11. }
  12. return StringIndexOf(q, p, 0) === 0;
  13. };