IsStringPrefix.js 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var isPrefixOf = require('../helpers/isPrefixOf');
  5. // var callBound = require('call-bind/callBound');
  6. // var $charAt = callBound('String.prototype.charAt');
  7. var Type = require('./Type');
  8. // https://262.ecma-international.org/9.0/#sec-isstringprefix
  9. module.exports = function IsStringPrefix(p, q) {
  10. if (Type(p) !== 'String') {
  11. throw new $TypeError('Assertion failed: "p" must be a String');
  12. }
  13. if (Type(q) !== 'String') {
  14. throw new $TypeError('Assertion failed: "q" must be a String');
  15. }
  16. return isPrefixOf(p, q);
  17. /*
  18. if (p === q || p === '') {
  19. return true;
  20. }
  21. var pLength = p.length;
  22. var qLength = q.length;
  23. if (pLength >= qLength) {
  24. return false;
  25. }
  26. // assert: pLength < qLength
  27. for (var i = 0; i < pLength; i += 1) {
  28. if ($charAt(p, i) !== $charAt(q, i)) {
  29. return false;
  30. }
  31. }
  32. return true;
  33. */
  34. };