main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
863 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var isPrefixOf = require('../helpers/isPrefixOf');
|
---|
6 |
|
---|
7 | // var callBound = require('call-bind/callBound');
|
---|
8 |
|
---|
9 | // var $charAt = callBound('String.prototype.charAt');
|
---|
10 |
|
---|
11 | // https://262.ecma-international.org/9.0/#sec-isstringprefix
|
---|
12 |
|
---|
13 | module.exports = function IsStringPrefix(p, q) {
|
---|
14 | if (typeof p !== 'string') {
|
---|
15 | throw new $TypeError('Assertion failed: "p" must be a String');
|
---|
16 | }
|
---|
17 |
|
---|
18 | if (typeof q !== 'string') {
|
---|
19 | throw new $TypeError('Assertion failed: "q" must be a String');
|
---|
20 | }
|
---|
21 |
|
---|
22 | return isPrefixOf(p, q);
|
---|
23 | /*
|
---|
24 | if (p === q || p === '') {
|
---|
25 | return true;
|
---|
26 | }
|
---|
27 |
|
---|
28 | var pLength = p.length;
|
---|
29 | var qLength = q.length;
|
---|
30 | if (pLength >= qLength) {
|
---|
31 | return false;
|
---|
32 | }
|
---|
33 |
|
---|
34 | // assert: pLength < qLength
|
---|
35 |
|
---|
36 | for (var i = 0; i < pLength; i += 1) {
|
---|
37 | if ($charAt(p, i) !== $charAt(q, i)) {
|
---|
38 | return false;
|
---|
39 | }
|
---|
40 | }
|
---|
41 | return true;
|
---|
42 | */
|
---|
43 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.