rittenhop-dev/versions/5.94.2/node_modules/@tryghost/helpers/lib/utils/count-images.js

17 lines
466 B
JavaScript
Raw Normal View History

2024-09-23 19:40:12 -04:00
/**
* Image count Utility
* @param {string} html
* @returns {integer} image count
* @description Takes an HTML string and returns the number of images
**/
export default function countImages(html) {
if (!html) {
return 0;
}
// protect against Handlebars.SafeString
if (Object.prototype.hasOwnProperty.call(html, 'string')) {
html = html.string;
}
return (html.match(/<img("[^"]*"|'[^']*'|[^'">])+\/?>/g) || []).length;
}