本文整理匯總了TypeScript中@angular-devkit/schematics.UpdateRecorder.insertLeft方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript UpdateRecorder.insertLeft方法的具體用法?TypeScript UpdateRecorder.insertLeft怎麽用?TypeScript UpdateRecorder.insertLeft使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular-devkit/schematics.UpdateRecorder
的用法示例。
在下文中一共展示了UpdateRecorder.insertLeft方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: replacePropertyInAstObject
function replacePropertyInAstObject(
recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue,
indent: number) {
const property = findPropertyInAstObject(node, propertyName);
if (property === null) {
throw new Error(`Property ${propertyName} does not exist in JSON object`);
}
const {start, text} = property;
recorder.remove(start.offset, text.length);
const indentStr = '\n' +
' '.repeat(indent);
const content = JSON.stringify(value, null, ' ').replace(/\n/g, indentStr);
recorder.insertLeft(start.offset, content);
}
示例2: appendValueInAstArray
export function appendValueInAstArray(
recorder: UpdateRecorder,
node: JsonAstArray,
value: JsonValue,
indent = 4,
) {
const indentStr = _buildIndent(indent);
if (node.elements.length > 0) {
// Insert comma.
const last = node.elements[node.elements.length - 1];
recorder.insertRight(last.start.offset + last.text.replace(/\s+$/, '').length, ',');
}
recorder.insertLeft(
node.end.offset - 1,
' '
+ JSON.stringify(value, null, 2).replace(/\n/g, indentStr)
+ indentStr.slice(0, -2),
);
}
示例3: appendPropertyInAstObject
function appendPropertyInAstObject(
recorder: UpdateRecorder,
node: JsonAstObject,
propertyName: string,
value: JsonValue,
indent = 4,
) {
const indentStr = '\n' + new Array(indent + 1).join(' ');
if (node.properties.length > 0) {
// Insert comma.
const last = node.properties[node.properties.length - 1];
recorder.insertRight(last.start.offset + last.text.replace(/\s+$/, '').length, ',');
}
recorder.insertLeft(
node.end.offset - 1,
' '
+ `"${propertyName}": ${JSON.stringify(value, null, 2).replace(/\n/g, indentStr)}`
+ indentStr.slice(0, -2),
);
}