本文整理汇总了TypeScript中lodash.repeat函数的典型用法代码示例。如果您正苦于以下问题:TypeScript repeat函数的具体用法?TypeScript repeat怎么用?TypeScript repeat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了repeat函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
() => {
const aHashtag = _.repeat( 'a', 139 );
const bHashtag = _.repeat( 'b', 140 ); // too long - don't link
const result = autolinker.link( `#${aHashtag} and #${bHashtag}` );
expect( result ).toBe( `<a href="${urlPrefix}/${aHashtag}">#${aHashtag}</a> and #${bHashtag}` );
} );
示例2: it
it( 'should link an instagram mention that is up to 30 characters long', () => {
const aUsername = _.repeat( 'a', 30 );
const bUsername = _.repeat( 'b', 31 ); // too long - don't link
const result = instagramAutolinker.link( `@${aUsername} and @${bUsername}` );
expect( result ).toBe( `<a href="https://instagram.com/${aUsername}">@${aUsername}</a> and @${bUsername}` );
} );
示例3: it
it("should validate Id format", () => {
//tslint:disable-next-line
interface Material extends ValidatableMixin {
}
class Material implements ValidatableMixin {
id: Stream<string>;
constructor(id: string) {
ValidatableMixin.call(this);
this.id = stream(id);
this.validateIdFormat("id");
}
}
applyMixins(Material, ValidatableMixin);
const badStrings = ["shaky salamander", ".hello", _.repeat("a", 256)];
badStrings.forEach((badString) => {
const material = new Material(badString);
material.validate();
expect(material.errors().hasErrors()).toBe(true);
expect(material.errors().errors("id"))
.toEqual(["Invalid id. This must be alphanumeric and can contain hyphens, underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."]);
});
});
示例4:
lines.forEach((line: string, index: number) => {
let newLine: string = (index < lines.length - 1) ? "\n" : "";
if (line && (index > 0 || !noIndentFirstLine))
result += _.repeat(" ", unitIndent * numIndent) + line + newLine;
else
result += line + newLine;
});
示例5: memoize
export const stringifyTreeNodeToXML = memoize((node: TreeNode, level: number = 0) => {
const tabs = repeat(" ", level * 2);
let buffer = `${tabs}<${node.name}`;
for (const namespace in node.attributes) {
const nsa = node.attributes[namespace];
for (const name in nsa) {
let value = nsa[name];
if (name === "style") {
value = stringifyStyle(value);
}
let attrName = name;
if (namespace !== DEFAULT_NAMESPACE) {
attrName = namespace + ":" + attrName;
}
buffer += ` ${attrName}=${JSON.stringify(value)}`
}
}
buffer += `>`;
if (node.children.length) {
buffer += `\n`;
}
buffer += node.children.map(child => stringifyTreeNodeToXML(child, level + 1)).join("");
buffer += `${node.children.length ? tabs : ""}</${node.name}>\n`;
return buffer;
});
示例6: Promise
return new Promise((resolve, reject) => {
this.error = false;
let customWordList = _.map(this.customWords, 'word');
if (!_.isEqual(this.mnemonicWords, customWordList)) {
return reject('Mnemonic string mismatch');
}
if (this.mnemonicHasPassphrase) {
let walletClient = this.bwcProvider.getClient();
let separator = this.useIdeograms ? '\u3000' : ' ';
let customSentence = customWordList.join(separator);
let password = this.password || '';
try {
walletClient.seedFromMnemonic(customSentence, {
network: this.wallet.credentials.network,
password,
account: this.wallet.credentials.account
});
} catch (err) {
walletClient.credentials.xPrivKey = _.repeat('x', 64);
return reject(err);
}
if (walletClient.credentials.xPrivKey.substr(walletClient.credentials.xPrivKey) != this.keys.xPrivKey) {
delete walletClient.credentials;
return reject('Private key mismatch');
}
}
this.profileProvider.setBackupFlag(this.wallet.credentials.walletId);
return resolve();
});
示例7: transform
transform(value: number) : string {
let numDigits = Math.max(Math.floor(Math.log(Math.abs(value)) / Math.LN10), 0) + 1;
let numZeroes = 3 - numDigits;
return `${_.repeat('0', numZeroes)}${value}`;
}
示例8: if
const transpileInferredProps = ({ type, properties }: Inference, path: string[] = []) => {
if (type === InferenceType.ANY) {
return `any`;
} else if (properties.$$each) {
let content = transpileInferredProps(properties.$$each, [...path, "$$each"]);
const buffer = [];
if (type & InferenceType.ARRAY) {
buffer.push(`Array<${content}>`);
}
if (type & InferenceType.OBJECT) {
buffer.push(`{ [identifier: string]:${content} }`);
}
return buffer.join(" | ");
} else if (type & InferenceType.OBJECT) {
let content = `{\n`;
for (const key in properties) {
content += repeat(" ", path.length * 2) + `${ATTRIBUTE_MAP[key] || key}: ${transpileInferredProps(properties[key], [...path, key])};\n`
}
// allow for any props for now. Will eventuall want to request for template
content += repeat(" ", (path.length) * 2) + "[identifier: string]: any;\n"
content += repeat(" ", (path.length - 1) * 2) + `}`;
return content;
} else {
let content = ``;
const buffer = [];
if (type & InferenceType.STRING) {
buffer.push("string");
}
if (type & InferenceType.NUMBER) {
buffer.push("number");
}
if (type & InferenceType.BOOLEAN) {
buffer.push("boolean");
}
return buffer.join(" | ");
}
}
示例9:
this.classes.filter(x => x.export).forEach(x => {
var name = x.name;
if (name === this.displayName) {
name = '_' + this.displayName;
}
lines.push(_.repeat(' ', indent + 4) + `class ${name} extends ${this.displayName}.${x.name} {}`);
});