MCPcopy Create free account
hub / github.com/RubyLouvre/anu / fromString

Function fromString

test/babel.js:45917–45939  ·  view source on GitHub ↗
(that, string, encoding)

Source from the content-addressed store, hash-verified

45915 };
45916
45917 function fromString(that, string, encoding) {
45918 if (typeof encoding !== 'string' || encoding === '') {
45919 encoding = 'utf8';
45920 }
45921
45922 if (!Buffer.isEncoding(encoding)) {
45923 throw new TypeError('"encoding" must be a valid string encoding');
45924 }
45925
45926 var length = byteLength(string, encoding) | 0;
45927 that = createBuffer(that, length);
45928
45929 var actual = that.write(string, encoding);
45930
45931 if (actual !== length) {
45932 // Writing a hex string, for example, that contains invalid characters will
45933 // cause everything after the first invalid character to be ignored. (e.g.
45934 // 'abxxcd' will be treated as 'ab')
45935 that = that.slice(0, actual);
45936 }
45937
45938 return that;
45939 }
45940
45941 function fromArrayLike(that, array) {
45942 var length = array.length < 0 ? 0 : checked(array.length) | 0;

Callers 1

fromFunction · 0.85

Calls 2

byteLengthFunction · 0.85
createBufferFunction · 0.85

Tested by

no test coverage detected