温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/v8/isStringOneByteRepresentation
点击访问原文链接

Node v8.isStringOneByteRepresentation function | API Reference | Bun

Node v8.isStringOneByteRepresentation function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:v8/isStringOneByteRepresentationFisStringOneByteRepresentation

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:v8/isStringOneByteRepresentationFisStringOneByteRepresentation

function

v8.isStringOneByteRepresentationfunction isStringOneByteRepresentation(content: string): boolean;

V8 only supports Latin-1/ISO-8859-1 and UTF16 as the underlying representation of a string. If the content uses Latin-1/ISO-8859-1 as the underlying representation, this function will return true; otherwise, it returns false.

If this method returns false, that does not mean that the string contains some characters not in Latin-1/ISO-8859-1. Sometimes a Latin-1 string may also be represented as UTF16.

const { isStringOneByteRepresentation } = require('node:v8');

const Encoding = {
latin1: 1,
utf16le: 2,
};
const buffer = Buffer.alloc(100);
function writeString(input) {
if (isStringOneByteRepresentation(input)) {
buffer.writeUint8(Encoding.latin1);
buffer.writeUint32LE(input.length, 1);
buffer.write(input, 5, 'latin1');
} else {
buffer.writeUint8(Encoding.utf16le);
buffer.writeUint32LE(input.length * 2, 1);
buffer.write(input, 5, 'utf16le');
}
}
writeString('hello');
writeString('你好');

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node v8.isStringOneByteRepresentation function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:v8.isStringOneByteRepresentation | Bun