UNPKG

google-fonts-cli

Version:

a quick way to add a google font to your project

101 lines (75 loc) 2.58 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: font-collection.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: font-collection.js</h1> <section> <article> <pre class="prettyprint source"><code>var B = require('boots-utils'); module.exports = FontCollection; /** * @constructor * @param {Font[]} data - A json blob from the google-fonts-api */ function FontCollection(data) { this.FONTS = data.items; } /** currently only searches for family */ FontCollection.prototype.find = function(options) { var family = options.family; for (var i = 0; i &lt; this.FONTS.length; i++) { if (this.FONTS[i].family === family) { return this.FONTS[i]; } } }; FontCollection.prototype.random = function(category, variants) { var fonts = []; // TODO - refactor. can this in one pass instead of two // TODO - resolve whether the parameters are treated as "and" or "or"w if (variants) { fonts = this.FONTS.filter(_fontVariantFilter); } if (category) { fonts = fonts.concat(this.FONTS.filter(_fontCategoryFilter)); } if (fonts.length === 0) fonts = this.FONTS; return B.array.randomInArray(fonts); function _fontCategoryFilter(font) { return font.category === category; } function _fontVariantFilter(font) { // TODO - optimize, low priority return variants.some(function(variant) { return font.variants.some(function(fontVariant) { return variant === fontVariant; }); }); } }; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="FontCollection.html">FontCollection</a></li><li><a href="Parser.html">Parser</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Sun May 31 2015 02:27:49 GMT-0700 (PDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>