本文整理汇总了TypeScript中@ephox/katamari.Strings.startsWith方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Strings.startsWith方法的具体用法?TypeScript Strings.startsWith怎么用?TypeScript Strings.startsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/katamari.Strings
的用法示例。
在下文中一共展示了Strings.startsWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: TreeWalker
const applyBlockPattern = (editor: Editor, pattern: BlockPattern) => {
const dom = editor.dom;
const rng = editor.selection.getRng();
const block = dom.getParent(rng.startContainer, dom.isBlock);
if (!block || !dom.is(block, 'p') || !isElement(block)) {
return;
}
const walker = new TreeWalker(block, block);
let node: Node;
let firstTextNode: Text;
while ((node = walker.next())) {
if (isText(node)) {
firstTextNode = node;
break;
}
}
if (!firstTextNode) {
return;
}
if (!Strings.startsWith(firstTextNode.data, pattern.start)) {
return;
}
if (Tools.trim(block.textContent).length === pattern.start.length) {
return;
}
// add a marker to store the cursor position
const cursor = editor.selection.getBookmark();
if (pattern.type === 'block-format') {
if (isBlockFormatName(pattern.format, editor.formatter)) {
editor.undoManager.transact(() => {
firstTextNode.deleteData(0, pattern.start.length);
editor.formatter.apply(pattern.format);
});
}
} else if (pattern.type === 'block-command') {
editor.undoManager.transact(() => {
firstTextNode.deleteData(0, pattern.start.length);
editor.execCommand(pattern.cmd, false, pattern.value);
});
}
// return the selection
editor.selection.moveToBookmark(cursor);
};
示例2:
const rgbToHex = (value: string) => Strings.startsWith(value, 'rgb') ? dom.toHex(value) : value;