css-url-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

CSS-URL

Utils for work with assets and urls in css

Extracted from postcss-url core

Encode

 
import { encodeFile } from 'css-url';
 
(async () => {
    const encodedStr = await encodeFile('./some/file.svg');
    // data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'...
 
    const encodedBase64Str = await encodeFile('./some/file.png');
    // "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAAAnRSTlMAAHaTzTgAAAAKSURBVHgBY2AAAAACAAFzdQEYAAAAAElFTkSuQmCC"
})
 

Parse

 
import { parse, replace } from 'css-url';
 
const parsedUrls = parse(`url('./someurl'), url(./another/path/url?query=1), url("./doublequotes/hash")`);
// parsed URL object array
 
replace('url(./another/path/url?query=1)', (url, before, after) => url.replace('another', 'my'));
// 'url(./my/path/url?query=1)'
 

Copy

 
import { copy } from 'css-url';
 
(async () => {
    const copiedFilePath = await copy('./some/file.svg', '/new/dest/name-[contenthash][ext]');
    // '/new/dest/file-23cgsd7b.svg'
})
 

Readme

Keywords

none

Package Sidebar

Install

npm i css-url-utils

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

17 kB

Total Files

12

Last publish

Collaborators

  • sergcen