本文整理匯總了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);