MCPcopy Create free account
hub / github.com/TruthHun/BookStack / fromString

Function fromString

static/word2md/mammoth.browser.js:9911–9933  ·  view source on GitHub ↗
(that, string, encoding)

Source from the content-addressed store, hash-verified

9909}
9910
9911function fromString (that, string, encoding) {
9912 if (typeof encoding !== 'string' || encoding === '') {
9913 encoding = 'utf8'
9914 }
9915
9916 if (!Buffer.isEncoding(encoding)) {
9917 throw new TypeError('"encoding" must be a valid string encoding')
9918 }
9919
9920 var length = byteLength(string, encoding) | 0
9921 that = createBuffer(that, length)
9922
9923 var actual = that.write(string, encoding)
9924
9925 if (actual !== length) {
9926 // Writing a hex string, for example, that contains invalid characters will
9927 // cause everything after the first invalid character to be ignored. (e.g.
9928 // 'abxxcd' will be treated as 'ab')
9929 that = that.slice(0, actual)
9930 }
9931
9932 return that
9933}
9934
9935function fromArrayLike (that, array) {
9936 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