You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IsStringPrefix.js 952B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. var GetIntrinsic = require('../GetIntrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var isPrefixOf = require('../helpers/isPrefixOf');
  5. // var callBound = require('../helpers/callBound');
  6. // var $charAt = callBound('String.prototype.charAt');
  7. var Type = require('./Type');
  8. // https://www.ecma-international.org/ecma-262/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. };