IsStringPrefix.js 539 B

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