itgalaxy / favicons

Favicons generator for Node.js
MIT License
1.19k stars 165 forks source link

Add feature to set different source image(s) for each platform. #431

Open hadimostafapour opened 1 year ago

hadimostafapour commented 1 year ago
  const options = {
    icons: {
      favicons: false,
      android: {
          source: ({width, height}) => {
                     return width < 800 ? "/path/to/foo" : "/path/to/bar";
           }
      },
      appleStartup: {
          offset: 2,
          source: "/path/to/asset"
      },
      windows: false,
      yandex: false,
      appleIcon: true,
    },
  };
andy128k commented 1 year ago

@hadimostafapour I like the direction where it goes, but I am not sure that such extension of config type is a right thing to do. Let's say, someone wants to specify a source for each platform individually, then they need to pass some dummy source to favicons() function to bypass a validator.

There are other ways to achieve similar result. E.g. extend

type Source = string | Buffer | (string | Buffer)[];
type PerPlatform<T> = Record<PlatformName | '*', T>;

export async function favicons(
  source: Source | PerPlatform<Source>,
  options: FaviconOptions = {}
): Promise<FaviconResponse> {
  // ...
}