当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript random.boolean方法代码示例

本文整理汇总了TypeScript中faker.random.boolean方法的典型用法代码示例。如果您正苦于以下问题:TypeScript random.boolean方法的具体用法?TypeScript random.boolean怎么用?TypeScript random.boolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在faker.random的用法示例。


在下文中一共展示了random.boolean方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

const createChannel = () => {
  return {
    id: faker.random.uuid(),
    name: faker.random.word(),
    direct: faker.random.boolean(),
    unseenMessages: faker.random.boolean() ? faker.random.number(30) : 0
  };
};
开发者ID:RocketChat,项目名称:Rocket.Chat.PWA,代码行数:8,代码来源:mocks.ts

示例2: modifyReplaceLeet

function modifyReplaceLeet(name: string): string {
    for (let letter in LEET_LANG) {
        if (faker.random.boolean()) {
            let regex = new RegExp(letter, faker.random.boolean() ? "g" : "");
            name = name.replace(regex, LEET_LANG[letter]);
        }
    }
    return name;
}
开发者ID:Tzook,项目名称:lul,代码行数:9,代码来源:randomNames.ts

示例3: getRandomPerson

export function getRandomPerson(options: GetRandomPersonOptions) {
  const opts: GetRandomPersonOptions = options || {};

  opts.maxDateOfBirth = opts.maxDateOfBirth || new Date(Date.now() - MS_IN_YEAR);
  opts.minAge = opts.minAge || 18;
  opts.maxAge = opts.maxAge || 105;
  opts.depth = opts.depth || 0;

  // Generates a family tree...of sorts
  const result: Person = {
    name: faker.name.lastName() + faker.name.firstName(),
    employment: {
      companyName: faker.company.companyName()
    },
    regex: /a/g,
    age: faker.random.number(),
    dateOfBirth: faker.date.past(),
    enrolledToVote: faker.random.boolean(),
  };

  if (opts.depth > 0) {
    result.parents = [
      getRandomPerson({ depth: opts.depth - 1 }),
      getRandomPerson({ depth: opts.depth - 1 })
    ];
  }

  return result;
}
开发者ID:codeandcats,项目名称:fast-clone,代码行数:29,代码来源:dataHelper.ts

示例4: 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;
}
开发者ID:Tzook,项目名称:lul,代码行数:18,代码来源:randomNames.ts

示例5: modifyAddDuplicateLetters

function modifyAddDuplicateLetters(name: string): string {
    let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
    const duplicationLetters: string[] = _.shuffle(DUPLICATION_LETTERS);
    for (let letter of duplicationLetters) {
        if (lengthAvailable > 0 && faker.random.boolean()) {
            name = name.replace(letter, letter + letter);
            lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
        }
    }
    return name;
}
开发者ID:Tzook,项目名称:lul,代码行数:11,代码来源:randomNames.ts

示例6: initDb

/** Create the database. */
async function initDb() {

    // Creates the file.
    try {
        await sequelize.authenticate();
        console.log('Connection to the database successful.');
    } catch (error) {
        console.log(`Error while trying to connect to the database: ${error}`);
    }

    // Syncs the model
    try {
        await sequelize.sync({force: true});
        console.log('Database sync sucessful');
    } catch (error) {
        console.log(`Error while trying to sync the model with the database : ${error}`);
    }

    if (process.env.DB_ENV !== 'prod') {
        // Populate the database with fake data
        try {
            let data: IArticle[] = [];
            for (let i = 0; i < 10; i++) {
                data.push({
                    title: faker.commerce.department(),
                    description: faker.lorem.sentence(),
                    content: faker.lorem.sentences(),
                    published: faker.random.boolean(),
                    publishedAt: new Date().toISOString()
                });
            }
            await Article.bulkCreate(data);
            console.log('10 articles successfully inserted.');
        } catch (error) {
            console.log(`Error while trying to insert an article in the database : ${error}`);
        }
    }
}
开发者ID:get-focus,项目名称:focus-help-center,代码行数:39,代码来源:init.ts

示例7: return

 return () => faker.random.boolean();
开发者ID:codeaudit,项目名称:graphql-faker,代码行数:1,代码来源:fake.ts


注:本文中的faker.random.boolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。