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

feat: add trimStart and trimEnd aliases #516

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ func builtinStringTrim(call FunctionCall) Value {
builtinStringTrimWhitespace))
}

func builtinStringTrimStart(call FunctionCall) Value {
return builtinStringTrimLeft(call)
}

func builtinStringTrimEnd(call FunctionCall) Value {
return builtinStringTrimRight(call)
}

// Mozilla extension, not ECMAScript 5.
func builtinStringTrimLeft(call FunctionCall) Value {
checkObjectCoercible(call.runtime, call.This)
Expand Down
76 changes: 76 additions & 0 deletions inline.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions inline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ func TestGetOwnPropertyNames(t *testing.T) {
"startsWith",
"toString",
"trim",
// "trimStart",
"trimLeft",
// "trimEnd",
"trimRight",
"trimStart",
"trimEnd",
"toLocaleLowerCase",
"toLocaleUpperCase",
"toLowerCase",
Expand Down
28 changes: 28 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,31 @@ func TestString_startsWith(t *testing.T) {
test(`'aa'.startsWith('a');`, true)
})
}

func TestString_trimStart(t *testing.T) {
tt(t, func() {
test, _ := test()

test(`" abc\u000B".trimStart()`, "abc\u000B")
test(`"abc ".trimStart()`, "abc ")
test(`
var a = "\u180Eabc \u000B "
var b = a.trimStart()
a.length + b.length
`, 13)
})
}

func TestString_trimEnd(t *testing.T) {
tt(t, func() {
test, _ := test()

test(`" abc\u000B".trimEnd()`, " abc")
test(`" abc ".trimEnd()`, " abc")
test(`
var a = "\u180Eabc \u000B "
var b = a.trimEnd()
a.length + b.length
`, 11)
})
}
214 changes: 109 additions & 105 deletions tools/gen-jscore/.gen-jscore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ types:
function: -1
- name: trimRight
function: -1
- name: trimStart
function: -1
- name: trimEnd
function: -1
- name: toLocaleLowerCase
function: -1
- name: toLocaleUpperCase
Expand Down Expand Up @@ -226,27 +230,27 @@ types:

- name: Number
properties:
- name: length
value: 1
- name: prototype
value: rt.global.NumberPrototype
- name: isNaN
function: 1
- name: MAX_VALUE
value: math.MaxFloat64
kind: valueNumber
- name: MIN_VALUE
kind: valueNumber
value: math.SmallestNonzeroFloat64
- name: NaN
kind: valueNumber
value: math.NaN()
- name: NEGATIVE_INFINITY
kind: valueNumber
value: math.Inf(-1)
- name: POSITIVE_INFINITY
kind: valueNumber
value: math.Inf(+1)
- name: length
value: 1
- name: prototype
value: rt.global.NumberPrototype
- name: isNaN
function: 1
- name: MAX_VALUE
value: math.MaxFloat64
kind: valueNumber
- name: MIN_VALUE
kind: valueNumber
value: math.SmallestNonzeroFloat64
- name: NaN
kind: valueNumber
value: math.NaN()
- name: NEGATIVE_INFINITY
kind: valueNumber
value: math.Inf(-1)
- name: POSITIVE_INFINITY
kind: valueNumber
value: math.Inf(+1)
prototype:
prototype: Object
value: prototypeValueNumber
Expand All @@ -270,90 +274,90 @@ types:
class: Math
objectPrototype: Object
properties:
- name: abs
function: 1
- name: acos
function: 1
- name: acosh
function: 1
- name: asin
function: 1
- name: asinh
function: 1
- name: atan
function: 1
- name: atanh
function: 1
- name: atan2
function: 1
- name: cbrt
function: 1
- name: ceil
function: 1
- name: cos
function: 1
- name: cosh
function: 1
- name: exp
function: 1
- name: expm1
function: 1
- name: floor
function: 1
- name: log
function: 1
- name: log10
function: 1
- name: log1p
function: 1
- name: log2
function: 1
- name: max
function: 2
- name: min
function: 2
- name: pow
function: 2
- name: random
function: -1
- name: round
function: 1
- name: sin
function: 1
- name: sinh
function: 1
- name: sqrt
function: 1
- name: tan
function: 1
- name: tanh
function: 1
- name: trunc
function: 1
- name: E
kind: valueNumber
value: math.E
- name: LN10
kind: valueNumber
value: math.Ln10
- name: LN2
kind: valueNumber
value: math.Ln2
- name: LOG10E
kind: valueNumber
value: math.Log10E
- name: LOG2E
kind: valueNumber
value: math.Log2E
- name: PI
kind: valueNumber
value: math.Pi
- name: SQRT1_2
kind: valueNumber
value: sqrt1_2
- name: SQRT2
kind: valueNumber
value: math.Sqrt2
- name: abs
function: 1
- name: acos
function: 1
- name: acosh
function: 1
- name: asin
function: 1
- name: asinh
function: 1
- name: atan
function: 1
- name: atanh
function: 1
- name: atan2
function: 1
- name: cbrt
function: 1
- name: ceil
function: 1
- name: cos
function: 1
- name: cosh
function: 1
- name: exp
function: 1
- name: expm1
function: 1
- name: floor
function: 1
- name: log
function: 1
- name: log10
function: 1
- name: log1p
function: 1
- name: log2
function: 1
- name: max
function: 2
- name: min
function: 2
- name: pow
function: 2
- name: random
function: -1
- name: round
function: 1
- name: sin
function: 1
- name: sinh
function: 1
- name: sqrt
function: 1
- name: tan
function: 1
- name: tanh
function: 1
- name: trunc
function: 1
- name: E
kind: valueNumber
value: math.E
- name: LN10
kind: valueNumber
value: math.Ln10
- name: LN2
kind: valueNumber
value: math.Ln2
- name: LOG10E
kind: valueNumber
value: math.Log10E
- name: LOG2E
kind: valueNumber
value: math.Log2E
- name: PI
kind: valueNumber
value: math.Pi
- name: SQRT1_2
kind: valueNumber
value: sqrt1_2
- name: SQRT2
kind: valueNumber
value: math.Sqrt2

- name: Date
properties:
Expand Down