UNPKG

react-native-skia-responsive-text

Version:

A library providing a wrapper for the React Native Skia Text component, offering features like user-friendly text alignment, efficient multiline text management, and straightforward text truncation.

35 lines 865 B
const isSpace = text => text.trim().length === 0; export const getTextChunks = text => { const splittedText = text.split(/(\s+)/g).filter(Boolean); const chunks = []; if (splittedText.length === 0) { return chunks; } const firstChunk = splittedText[0]; let prefix = ''; let i = 0; if (isSpace(firstChunk)) { prefix = firstChunk; i++; } for (; i < splittedText.length; i++) { const chunk = prefix + splittedText[i]; prefix = ''; const nextChunk = splittedText[i + 1]; if (nextChunk && isSpace(nextChunk)) { chunks.push(chunk + nextChunk); i++; } else { chunks.push(chunk); } } return chunks; }; export const mergeLines = lines => lines.reduce((acc, line) => ({ text: acc.text + line.text, width: acc.width + line.width }), { text: '', width: 0 }); //# sourceMappingURL=text.js.map