MCPcopy Create free account
hub / github.com/microsoft/SandDance / fromString

Function fromString

docs/tests/v2/es6/js/sanddance.js:78591–78613  ·  view source on GitHub ↗
(that, string, encoding)

Source from the content-addressed store, hash-verified

78589}
78590
78591function fromString (that, string, encoding) {
78592 if (typeof encoding !== 'string' || encoding === '') {
78593 encoding = 'utf8'
78594 }
78595
78596 if (!Buffer.isEncoding(encoding)) {
78597 throw new TypeError('"encoding" must be a valid string encoding')
78598 }
78599
78600 var length = byteLength(string, encoding) | 0
78601 that = createBuffer(that, length)
78602
78603 var actual = that.write(string, encoding)
78604
78605 if (actual !== length) {
78606 // Writing a hex string, for example, that contains invalid characters will
78607 // cause everything after the first invalid character to be ignored. (e.g.
78608 // 'abxxcd' will be treated as 'ab')
78609 that = that.slice(0, actual)
78610 }
78611
78612 return that
78613}
78614
78615function fromArrayLike (that, array) {
78616 var length = array.length < 0 ? 0 : checked(array.length) | 0

Callers 1

fromFunction · 0.70

Calls 2

byteLengthFunction · 0.70
createBufferFunction · 0.70

Tested by

no test coverage detected