How to use the @dicebear/avatars/lib/color.collection function in @dicebear/avatars

To help you get started, we’ve selected a few @dicebear/avatars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DiceBear / avatars / packages / avatars-initials-sprites / src / index.ts View on Github external
};

  let backgroundColors: string[] = [];
  let isInternetExplorer =
    options.userAgent &&
    Bowser.getParser(options.userAgent).satisfies({
      ie: '>0',
      edge: '>0'
    });
  let isSafari =
    options.userAgent &&
    Bowser.getParser(options.userAgent).satisfies({
      safari: '>0'
    });

  Object.keys(Color.collection).forEach((backgroundColor: keyof ColorCollection) => {
    if (
      options.backgroundColors === undefined ||
      options.backgroundColors.length === 0 ||
      options.backgroundColors.indexOf(backgroundColor) !== -1
    ) {
      backgroundColors.push(Color.collection[backgroundColor][options.backgroundColorLevel]);
    }
  });

  return function(random: Random) {
    let backgroundColor = random.pickone(backgroundColors);
    let seedInitials = (initials(random.seed.trim()) as string).toLocaleUpperCase().slice(0, options.chars);
    let fontFamily = "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif";

    // prettier-ignore
    return [
github DiceBear / avatars / packages / avatars-identicon-sprites / src / index.ts View on Github external
export default function(options: Options = {}) {
  options = {
    padding: 0,
    background: '#FFF',
    colorLevel: 600,
    ...options
  };

  let colors: string[] = [];

  Object.keys(Color.collection).forEach((color: keyof ColorCollection) => {
    if (options.colors === undefined || options.colors.length === 0 || options.colors.indexOf(color) !== -1) {
      colors.push(Color.collection[color][options.colorLevel]);
    }
  });

  return function(random: Random) {
    let color = random.pickone(colors);

    // prettier-ignore
    return [
      `<svg shape-rendering="crispEdges" version="1.1" viewBox="${0-options.padding} ${0-options.padding} ${5+options.padding*2} ${5+options.padding*2}" style="isolation:isolate" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">`,
      // Background
      `<path fill="${options.background}" d="M${0-options.padding} ${0-options.padding}h${5+options.padding*2}v${5+options.padding*2}H${0-options.padding}V0z"></path>`,
      // Row 1
      random.pickone([
        `<path fill="${color}" fill-rule="evenodd" d="M0 4h1v1H0V4zm4 0h1v1H4V4z"></path>`,</svg>
github DiceBear / avatars / packages / avatars-bottts-sprites / src / index.ts View on Github external
Object.keys(Color.collection).forEach((color: keyof ColorCollection) => {
    if (options.colors === undefined || options.colors.length === 0 || options.colors.indexOf(color) !== -1) {
      colorsCollection.push(Color.collection[color]);
    }
  });
github DiceBear / avatars / packages / avatars-initials-sprites / src / index.ts View on Github external
Object.keys(Color.collection).forEach((backgroundColor: keyof ColorCollection) => {
    if (
      options.backgroundColors === undefined ||
      options.backgroundColors.length === 0 ||
      options.backgroundColors.indexOf(backgroundColor) !== -1
    ) {
      backgroundColors.push(Color.collection[backgroundColor][options.backgroundColorLevel]);
    }
  });
github DiceBear / avatars / packages / avatars-identicon-sprites / src / index.ts View on Github external
Object.keys(Color.collection).forEach((color: keyof ColorCollection) => {
    if (options.colors === undefined || options.colors.length === 0 || options.colors.indexOf(color) !== -1) {
      colors.push(Color.collection[color][options.colorLevel]);
    }
  });
github DiceBear / avatars / packages / avatars-bottts-sprites / src / index.ts View on Github external
textureChance: 50,
    topChange: 100,
    ...options
  };

  const group = (random: Random, content: string, chance: number, x: number, y: number) =&gt; {
    if (random.bool(chance)) {
      return ``;
    }

    return '';
  };

  let colorsCollection: Array = [];

  Object.keys(Color.collection).forEach((color: keyof ColorCollection) =&gt; {
    if (options.colors === undefined || options.colors.length === 0 || options.colors.indexOf(color) !== -1) {
      colorsCollection.push(Color.collection[color]);
    }
  });

  return function(random: Random) {
    let primaryColorCollection = random.pickone(colorsCollection);
    let secondaryColorCollection = random.pickone(colorsCollection);

    let primaryColor = new Color(primaryColorCollection[options.primaryColorLevel]);
    let secondaryColor = new Color(primaryColorCollection[options.secondaryColorLevel]);

    if (options.colorful) {
      secondaryColor = new Color(secondaryColorCollection[options.secondaryColorLevel]);
    }

@dicebear/avatars

An avatar library for designers and developers.

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis