本文整理汇总了TypeScript中src/string.raw函数的典型用法代码示例。如果您正苦于以下问题:TypeScript raw函数的具体用法?TypeScript raw怎么用?TypeScript raw使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raw函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
assert.throws(function () {
stringUtil.raw(null);
}, TypeError);
示例2: getCallSite
assert.throws(function () {
stringUtil.raw(null);
}, TypeError);
},
'basic tests'() {
let answer = 42;
assert.strictEqual(stringUtil.raw`The answer is:\n${answer}`, 'The answer is:\\n42',
'stringUtil.raw applied to template string should result in expected value');
function getCallSite(callSite: TemplateStringsArray, ...substitutions: any[]) {
return callSite;
}
let callSite = getCallSite`The answer is:\n${answer}`;
assert.strictEqual(stringUtil.raw(callSite), 'The answer is:\\n',
'stringUtil.raw applied with insufficient arguments should result in no substitution');
callSite.raw = [ 'The answer is:\\n' ];
assert.strictEqual(stringUtil.raw(callSite, 42), 'The answer is:\\n',
'stringUtil.raw applied with insufficient raw fragments should result in truncation before substitution');
}
},
'.repeat()': {
'throws on undefined or null string'() {
assert.throws(function () {
stringUtil.repeat(undefined);
}, TypeError);
assert.throws(function () {
stringUtil.repeat(null);