itgalaxy / favicons

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

HTML Object Return - Add option to return html un-stringified (for use in libraries/plugins) #443

Open josh-hemphill opened 12 months ago

josh-hemphill commented 12 months ago

closes #442 In other libraries/plugins, it's necessary to separately apply tag data and/or add their own, while still mostly following what favicons supplies.

It took more modification than I'd like to get all the types to return based on the options, but I seem to have got it right, all the tests pass (even made sure the tag order is the same so the snapshots pass), and the return types behave as I'd expect.

andy128k commented 12 months ago

Other option would be to expand FaviconResponse and add one more field.

export interface FaviconResponse {
  readonly images: FaviconImage[];
  readonly files: FaviconFile[];
  readonly html: FaviconHtmlElement[]; // string[]
  readonly htmlTags: FaviconHtmlTag[];
}

Then use htmlTags internally and convert htmlTags to html before a return. wdyt?

josh-hemphill commented 12 months ago

That's kind of what I have it doing. But the different return type means that if you're using the un-stringified return, the stringification doesn't even have to run. Yeah, I guess it does mean not having the complex generic types, but at the cost of a little more having to run at runtime. I'll go ahead and make the change.

josh-hemphill commented 12 months ago

Okay, the additional return did simplify things. Had to update most of the snapshots for the tests.