本文整理汇总了TypeScript中faker.random.arrayElement方法的典型用法代码示例。如果您正苦于以下问题:TypeScript random.arrayElement方法的具体用法?TypeScript random.arrayElement怎么用?TypeScript random.arrayElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类faker.random
的用法示例。
在下文中一共展示了random.arrayElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: modifyAddPrefix
function modifyAddPrefix(name: string, isMale: boolean): string {
let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
if (faker.random.boolean()) {
const perk = faker.random.objectElement(talentsConfig.PERKS);
const perkWords = perk.split(/(?=[A-Z])/);
if (lengthAvailable >= perkWords[0].length) {
return capitalizeFirstLetter(perkWords[0]) + name;
}
}
if (faker.random.boolean()) {
const color = faker.commerce.color().replace(/ /g, "");
if (lengthAvailable >= color.length) {
return capitalizeFirstLetter(color) + name;
}
}
const prefixes = COMMON_PREFIXES.concat(isMale ? MALE_PREFIXES : FEMALE_PREFIXES).filter(prefix => prefix.length <= lengthAvailable);
return (prefixes.length > 0 ? faker.random.arrayElement(prefixes) : "") + name;
}
示例2: modifyAddWrap
function modifyAddWrap(name: string): string {
let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
let l, l1, l2, l3;
l = faker.random.arrayElement(WRAP_LETTERS);
l1 = faker.random.number(2) === 0 ? l.toUpperCase() : l;
l2 = faker.random.number(2) === 0 ? l.toUpperCase() : l;
l3 = faker.random.number(2) === 0 ? l.toUpperCase() : l;
switch (lengthAvailable) {
case 0: case 1: return name;
case 2: case 3: return single();
case 4: case 5: return double();
default: case 6: case 7:
switch (faker.random.number(2)) {
case 0: return single();
case 1: return double();
default: case 2: return triple();
}
}
function single() {
return `${l1}${name}${l1}`;
}
function double() {
if (l === "x" && faker.random.number(3) === 0) {
// add d so it will look like xD
l2 = l2 === "x" ? "d" : "D";
}
let start = l1 + l2;
if (faker.random.number(3) === 0) {
start = "";
}
return `${start}${name}${l2}${l1}`;
}
function triple() {
return `${l1}${l2}${l3}${name}${l3}${l2}${l1}`;
}
}
示例3: modifyAddSuffix
function modifyAddSuffix(name: string, isMale: boolean): string {
let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
const suffixes = COMMON_SUFFIXES.concat(isMale ? MALE_SUFFIXES : FEMALE_SUFFIXES).filter(suffix => suffix.length <= lengthAvailable);
return name + (suffixes.length > 0 ? faker.random.arrayElement(suffixes) : "");
}
示例4: modifyAddSinglePrefix
function modifyAddSinglePrefix(name: string): string {
let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
return (lengthAvailable > 0 ? faker.random.arrayElement(SINGLE_LETTER_PREFIXES) : "") + name;
}
示例5: randomRelationshipType
public static randomRelationshipType() {
return faker.random.arrayElement([
'Business', 'Online Service Provider'
]);
}