MCPcopy Create free account
hub / github.com/dop251/goja / stringproto_normalize

Method stringproto_normalize

builtin_string.go:443–480  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

441}
442
443func (r *Runtime) stringproto_normalize(call FunctionCall) Value {
444 r.checkObjectCoercible(call.This)
445 s := call.This.toString()
446 var form string
447 if formArg := call.Argument(0); formArg != _undefined {
448 form = formArg.toString().toString().String()
449 } else {
450 form = "NFC"
451 }
452 var f norm.Form
453 switch form {
454 case "NFC":
455 f = norm.NFC
456 case "NFD":
457 f = norm.NFD
458 case "NFKC":
459 f = norm.NFKC
460 case "NFKD":
461 f = norm.NFKD
462 default:
463 panic(r.newError(r.getRangeError(), "The normalization form should be one of NFC, NFD, NFKC, NFKD"))
464 }
465
466 switch s := s.(type) {
467 case asciiString:
468 return s
469 case unicodeString:
470 ss := s.String()
471 return newStringValue(f.String(ss))
472 case *importedString:
473 if s.scanned && s.u == nil {
474 return asciiString(s.s)
475 }
476 return newStringValue(f.String(s.s))
477 default:
478 panic(unknownStringTypeErr(s))
479 }
480}
481
482func (r *Runtime) _stringPad(call FunctionCall, start bool) Value {
483 r.checkObjectCoercible(call.This)

Callers

nothing calls this directly

Calls 9

checkObjectCoercibleMethod · 0.95
newErrorMethod · 0.95
getRangeErrorMethod · 0.95
newStringValueFunction · 0.85
asciiStringTypeAlias · 0.85
unknownStringTypeErrFunction · 0.85
toStringMethod · 0.65
StringMethod · 0.65
ArgumentMethod · 0.45

Tested by

no test coverage detected