Socket
Socket
Sign inDemoInstall

google-fonts-css2

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-fonts-css2 - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

dist/cjs/index.js

91

package.json
{
"name": "google-fonts-css2",
"version": "1.0.3",
"private": false,
"description": "A helper package to interact with google fonts API.",
"author": "Adriano Tirloni",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/adriano-tirloni/google-fonts-css2.git"
},
"homepage": "https://github.com/adriano-tirloni/google-fonts-css2",
"bugs": {
"url": "https://github.com/adriano-tirloni/google-fonts-css2/issues",
"email": "tirloni.adriano@gmail.com"
},
"main": "index.js",
"engines": {
"node": ">=8",
"npm": ">=5"
},
"scripts": {
"prepublishOnly": "yarn release",
"release": "yarn build:dev && yarn build:prod",
"build:prod": "NODE_ENV=production rollup -c",
"build:dev": "NODE_ENV=development rollup -c"
},
"dependencies": {},
"peerDependencies": {},
"devDependencies": {
"@babel/core": "^7.11.4",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/preset-env": "^7.11.0",
"babel-loader": "^8.1.0",
"rollup": "^1.29.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0"
},
"files": [
"dist"
],
"keywords": ["google", "google fonts", "fonts", "css2", "google fonts api", "google fonts url"]
"name": "google-fonts-css2",
"version": "2.0.0",
"description": "A Javascript package to integrate with Google Fonts API.",
"author": "Adriano Tirloni",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/adriano-tirloni/google-fonts-css2.git"
},
"homepage": "https://github.com/adriano-tirloni/google-fonts-css2",
"bugs": {
"url": "https://github.com/adriano-tirloni/google-fonts-css2/issues",
"email": "tirloni.adriano@gmail.com"
},
"//comment// main & module": "main and module keys are present for backwards compaibility, read on : https://nodejs.org/api/packages.html#dual-commonjses-module-packages",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
},
"scripts": {
"examples-esm": "node ./examples/esm/examples.mjs",
"examples-cjs": "node ./examples/cjs/examples.cjs",
"build": "rollup -c && bash ./postbuild"
},
"devDependencies": {
"rollup": "^2.77.0",
"rollup-plugin-terser": "^7.0.2"
},
"files": [
"dist/"
],
"keywords": [
"google",
"google fonts",
"fonts",
"css2",
"variable fonts",
"google fonts api",
"google fonts url",
"material icons",
"material symbols"
],
"engines": {
"node": ">=8",
"npm": ">=5"
}
}

@@ -1,84 +0,46 @@

# Google Fonts CSS2
# 📃GOOGLE FONT CSS 2
## A Javascript package to integrate with Google Fonts API.
This package is supposed to be an agnostic and fast helper package to interact with Google Fonts API version 2.
⚠️ *If you were using the v1 of this package check the new API below, it is slightly different. *
**`React Component`: [https://github.com/adriano-tirloni/react-google-fonts-css2](https://github.com/adriano-tirloni/react-google-fonts-css2)**
This is a package with a **single purpose**: To provide an easy interface to create the latest version of a Google Fonts CSS2 URL.
- It adheres to the rules described on [the current Google Fonts Documentation (CSS2)](https://developers.google.com/fonts/docs/css2 "Google Fonts Documentation (CSS2)").
- Works on browser and server side (**SSR**).
- Can create** Material Symbols** and **Material Icons** URLs
### URL Builder:
Read on for more information.
Feel free to open issues or PRs.
URL Builder for V2 has 2 functions:
`assembleCommom` - working
`assembleFull` - to be developed as needed
------------
##### How it works?
> **You say**:
Gimme **Open Sans**, from **light to bold**, **italic**. **condensed** and **normal**!
1) **`assembleCommon`**: This function works as described below, and will request fonts with styles varying on **weight** and being **italic**. It was developed to be fast and not to include all possible scenarios. For the full flexible API there is the `assembleFull` function.
> **It answers:**
[https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@1,75,300..700&family=Open+Sans:ital,wdth,wght@1,100,300..700&display=auto](https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@1,75,300..700&family=Open+Sans:ital,wdth,wght@1,100,300..700&display=auto)
------------
- **Get Started**
- **NodeJS, Browser, Common-JS, ES-Modules**
- **Functions**
- **Android, IOS & Flutter**
- **Google Fonts**
- **Regular Fonts**
- **Variable Fonts**
- **Variable Fonts Options**
- **Google Material Symbols**
- **Variable Symbols Options**
- **Google Material Icons**
- **Validations**
- **Examples**
2) **`assembleFull`**: **not developed** - This function will take a different structure from assembleCommon to be able to render the full spec of Google Font API axis:
---
## Get Started
asd
- Italic - `ital`
- Optical Size - `opsz`
- Slant - `slnt`
- Weight - `wght`
- Width - `wdth`
- Casual - `CASL`
- Cursive - `CRSV`
- Expression - `XPRN`
- Grade - `GRAD`
- Monospace - `MONO`
- Softness - `SOFT`
- Wonkiness - `WONK`
[https://developers.google.com/fonts/docs/css2](https://developers.google.com/fonts/docs/css2)
[https://fonts.google.com/variablefonts](https://fonts.google.com/variablefonts)
## Usage:
```javascript
const { assembleCommon } = require("google-fonts-css2"
//or
import { assembleCommon } from "google-fonts-css2"
// assembleCommon(Array:families, String:display)
let url = assembleCommon([
{
family: "Cabin", // Family Name
styles: [
"600..700", // Range, if family supports it.
"100..200italic", // Range with italic
"300italic", // Weight with italic
"regular", // Shortcut to 400
"italic", // Shortcut to 400 Italic
"500", // Regular with weight
444 // Regular weight for variable font
]
},
{
family: "Roboto", // Family Name - Roboto doesn't support ranges
styles: [
"300italic", // Weight with italic
"regular", // Shortcut to 400
"italic", // Shortcut to 400 Italic
"500",
100
]
},
], 'swap') // Display Style
// The output will be:
"https://fonts.googleapis.com/css2?family=Cabin:ital,wght@0,400;0,444;0,500;0,600..700;1,100..200;1,300;1,400;1,600..700&family=Roboto:ital,wght@0,100;0,400;0,500;1,300;1,400&display=auto"
```
Check it here: [https://fonts.googleapis.com/css2?family=Cabin:ital,wght@0,400;0,444;0,500;0,600..700;1,100..200;1,300;1,400;1,600..700&family=Roboto:ital,wght@0,100;0,400;0,500;1,300;1,400&display=auto](https://fonts.googleapis.com/css2?family=Cabin:ital,wght@0,400;0,444;0,500;0,600..700;1,100..200;1,300;1,400;1,600..700&family=Roboto:ital,wght@0,100;0,400;0,500;1,300;1,400&display=auto)
## Example | Test
Run:
```bash
git clone git@github.com:adriano-tirloni/google-fonts-css2.git
yarn
yarn build:dev
node ./src/example.js
```
## Input Validation
✅ Validates the existence of the directive axis used. (`weight or wght`, `opticalSize or opsz`)
✅ Ignores duplicate directives (`wght`) and uses the latest one.
❌ Does **not** validate if the font requested has the directive in its options. Eg: If you request **Open Sans**, asking for `slant -10` the URL will properly be created **BUT** Google will return a `400` answer as the **slant** directive is not avaliable for **Open Sans**
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc