Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement trimStart/trimEnd #5690

Closed
dilijev opened this issue Sep 11, 2018 · 1 comment
Closed

Implement trimStart/trimEnd #5690

dilijev opened this issue Sep 11, 2018 · 1 comment
Assignees
Labels

Comments

@dilijev
Copy link
Contributor

dilijev commented Sep 11, 2018

Ported from OS#18780560

Stage 3 Proposal: https://github.com/tc39/proposal-string-left-right-trim
We already have implementations of trimLeft and trimRight, so we simply need to add trimStart and trimEnd as aliases to those.

>es --tags jsvu-web -is E:\work\bugs\19h1\trimStart-trimEnd\trimStart-trimEnd.js
## Source
let stringToTrim = '  hello  '
function trimIt(trimmerFn) {
    return '.' + trimmerFn.call(stringToTrim) + '.';
}
function has(funcName) {
    let doesHave = String.prototype.hasOwnProperty(funcName);
    let doesHaveString = doesHave ? '++ yes ++' : '-- NO --'
    print(`has ${funcName}? ${doesHaveString}`);
    if (doesHave) {
        print(trimIt(String.prototype[funcName]))
    }
}
has('trimLeft')
has('trimRight')
has('trimStart')
has('trimEnd')

#### jsvu-ch
has trimLeft? ++ yes ++
.hello  .
has trimRight? ++ yes ++
.  hello.
has trimStart? -- NO --
has trimEnd? -- NO --
#### jsvu-jsc, jsvu-sm, jsvu-v8
has trimLeft? ++ yes ++
.hello  .
has trimRight? ++ yes ++
.  hello.
has trimStart? ++ yes ++
.hello  .
has trimEnd? ++ yes ++
.  hello.
@dilijev dilijev added the Task label Sep 11, 2018
sharmasuraj0123 added a commit to sharmasuraj0123/ChakraCore that referenced this issue Sep 11, 2018
sharmasuraj0123 added a commit to sharmasuraj0123/ChakraCore that referenced this issue Sep 14, 2018
@dilijev
Copy link
Contributor Author

dilijev commented Sep 15, 2018

Another set of test cases:

>eshost --tags jsvu-web -is test.js
## Source
let assert = {
    areEqual(a, b) {
        if (a !== b) {
            print(`FAIL: expected ${a} === ${b}`);
        }
    }
}

assert.areEqual(String.prototype.trimLeft, String.prototype.trimStart);
assert.areEqual(String.prototype.trimRight, String.prototype.trimEnd);

if (String.prototype.trimStart) {
    assert.areEqual(String.prototype.trimStart.name, 'trimStart')
} else {
    print("FAIL: String.prototype.trimStart should not be undefined")
}

if (String.prototype.trimEnd) {
    assert.areEqual(String.prototype.trimEnd.name, 'trimEnd')
} else {
    print("FAIL: String.prototype.trimEnd should not be undefined")
}

assert.areEqual(String.prototype.trimLeft.name, 'trimStart')
assert.areEqual(String.prototype.trimRight.name, 'trimEnd')

print("DONE")


#### jsvu-ch
FAIL: expected function trimLeft() { [native code] } === undefined
FAIL: expected function trimRight() { [native code] } === undefined
FAIL: String.prototype.trimStart should not be undefined
FAIL: String.prototype.trimEnd should not be undefined
FAIL: expected trimLeft === trimStart
FAIL: expected trimRight === trimEnd
DONE

#### jsvu-jsc, jsvu-sm, jsvu-v8
DONE

sharmasuraj0123 added a commit to sharmasuraj0123/ChakraCore that referenced this issue Sep 15, 2018
chakrabot pushed a commit that referenced this issue Sep 15, 2018
Merge pull request #5693 from sharmasuraj0123:trimStart_trimEnd

Fixes #5690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants