init commit
This commit is contained in:
36
remotion/node_modules/@remotion/renderer/dist/assets/truncate-utf8-bytes.js
generated
vendored
Normal file
36
remotion/node_modules/@remotion/renderer/dist/assets/truncate-utf8-bytes.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.truncateUtf8Bytes = truncateUtf8Bytes;
|
||||
function isHighSurrogate(codePoint) {
|
||||
return codePoint >= 0xd800 && codePoint <= 0xdbff;
|
||||
}
|
||||
function isLowSurrogate(codePoint) {
|
||||
return codePoint >= 0xdc00 && codePoint <= 0xdfff;
|
||||
}
|
||||
const getLength = Buffer.byteLength.bind(Buffer);
|
||||
function truncateUtf8Bytes(string, byteLength) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new Error('Input must be string');
|
||||
}
|
||||
const charLength = string.length;
|
||||
let curByteLength = 0;
|
||||
let codePoint;
|
||||
let segment;
|
||||
for (let i = 0; i < charLength; i += 1) {
|
||||
codePoint = string.charCodeAt(i);
|
||||
segment = string[i];
|
||||
if (isHighSurrogate(codePoint) &&
|
||||
isLowSurrogate(string.charCodeAt(i + 1))) {
|
||||
i += 1;
|
||||
segment += string[i];
|
||||
}
|
||||
curByteLength += getLength(segment);
|
||||
if (curByteLength === byteLength) {
|
||||
return string.slice(0, i + 1);
|
||||
}
|
||||
if (curByteLength > byteLength) {
|
||||
return string.slice(0, i - segment.length + 1);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
Reference in New Issue
Block a user