IsStringPrefix.js 863 B

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