Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-font-grabber

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-font-grabber - npm Package Compare versions

Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2

1

dist/index.d.ts
import { PluginCreator } from 'postcss';
import { PluginOptions } from './types';
declare const postcssFontGrabber: PluginCreator<PluginOptions>;
export { FontSpec, Downloader, DownloadResult } from './types';
export { postcssFontGrabber };
export default postcssFontGrabber;

4

package.json
{
"name": "postcss-font-grabber",
"version": "3.0.0-alpha.1",
"description": "Grab remote font files in @font-face, download them and update your CSS, just like that.",
"version": "3.0.0-alpha.2",
"description": "It grabs remote font files and update your CSS, just like that.",
"author": "AaronJan <aaronjan@qq.com>",

@@ -6,0 +6,0 @@ "homepage": "https://github.com/AaronJan/postcss-font-grabber",

@@ -15,3 +15,3 @@ <h1 align=center>

A [`PostCSS`](https://github.com/postcss/postcss) plugin, it only does one thing and good at it: **download remote fonts, and update the corresponding `@font-face` rules**.
A [`postcss`](https://github.com/postcss/postcss) plugin, it grabs remote font files and update your CSS, just like that.

@@ -31,2 +31,3 @@ > `postcss-font-grabber` `v3.x` only works with `postcss` `v8`,for `postcss` `v7`, please take a look at the [`v2.x`](https://github.com/AaronJan/postcss-font-grabber/tree/v1.x).

- Support custom download function (the `download` option)
- Written in TypeScript

@@ -46,2 +47,31 @@ - Standalone without any dependency

### Options
```typescript
import { postcssFontGrabber, FontSpec } from 'postcss-font-grabber';
import { Readable } from 'stream';
postcssFontGrabber({
// The path of the source CSS directory.
// Normally you don't have to set this.
cssSrc: 'src/css/',
// The path of the CSS output directory.
// You have to specify this manually, PFG needs this to calculate relative
// path.
cssDest: 'src/css/',
// The directory to store the downloaded font files.
// It's the same as `cssDest` by default.
fontDest: 'tmp/css/fonts/',
// Custom function to download font files.
// Optional.
download: async (fontSpec: FontSpec) => ({
data: Readable.from(['font file content']),
mimeType: 'application/font-woff2',
}),
}),
```
### With Gulp

@@ -59,8 +89,6 @@

postcssFontGrabber({
// Because PostCSS-Font-Grabber can't get the paths outside itself, you
// have to set them manually.
cssSrc: 'src/css/',
// postcss-font-grabber needs to know the CSS output
// directory in order to calculate the new font URL.
cssDest: 'dist/',
fontDest: 'dist/fonts/',
mkdir: true,
}),

@@ -154,3 +182,2 @@ ]),

fontDest: 'dist/fonts/',
mkdir: true,
});

@@ -166,65 +193,6 @@ ```

## Dig Deeper
## Advanced Usages
You can get the **metadata** of all execution details of `PostCSS-Font-Grabber`:
TODO
```javascript
import postcss from 'gulp-postcss';
import { makeInstance } from 'postcss-font-grabber';
gulp.task('default', () => {
// Create instance manually:
const fontGrabber = makeInstance({
cssSrc: 'src/css/',
cssDest: 'dist/',
fontDest: 'dist/fonts/',
mkdir: true,
});
// Register a callback:
fontGrabber.onDone(meta => {
console.log('meta', JSON.stringify(meta, null, ' '));
});
return gulp
.src('src/css/**/*.css')
.pipe(postcss([fontGrabber.makeTransformer()]))
.pipe(gulp.dest('dist/'));
});
```
### Metadata Format
Here is an example:
```javascript
// Importing module just for demonstration purpose, because the metadata contains URL object.
import url from 'url';
{
"jobResults": [
{
"job": {
"remoteFont": {
"urlObject": url.parse('https://example.com'),
"format": "woff2"
},
"css": {
"sourcePath": "/var/project/public/css/google.css",
"destinationDirectoryPath": "/var/project/public/dist/css/fonts"
},
"font": {
"path": "/var/project/public/dist/css/fonts/ea8XadU7WuTxEub_NdWn8WZFuVs.woff2",
"filename": "ea8XadU7WuTxEub_NdWn8WZFuVs.woff2"
}
},
"download": {
"size": 14312
}
},
/* More JobResults */
]
}
```
## License

@@ -231,0 +199,0 @@

Sorry, the diff of this file is not supported yet

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