Socket
Socket
Sign inDemoInstall

css-fruit

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css-fruit

A Parser and Analysis of CSS Declaration


Version published
Weekly downloads
216
increased by30.91%
Maintainers
1
Install size
537 kB
Created
Weekly downloads
 

Readme

Source

css-fruit

  • 中文说明

A Parser and Analysis of CSS Declaration.

CircleCI NPM Version Dependencies NPM Download

Features

  • Can set parse depth
  • Chained call
  • ...

Install

npm install --save-dev css-fruit

Example

Quickstart

import Fruit from 'css-fruit';

const background = Fruit.absorb('background', 'url(abc.png) #eee right top / 100% repeat-x');

CommonJS Code

const Fruit = require('css-fruit').default;

const background = Fruit.absorb('background', 'url(abc.png) #eee right top / 100% repeat-x');

Following is the structure of generated backgroud object:

background: Background {
    valid: true,
    color: #eee,
    image: 'url(\'abc.png\')',
    position: BackgroundPosition {
        valid: true,
        x: { origin: 'right', offset: undefined },
        y: { origin: 'top', offset: undefined },
    },
    size: BackgroundSize {
        valid: true,
        width: '100%',
        height: 'auto',
    },
    repeat: BackgroundRepeat {
        valid: true,
        x: 'repeat',
        y: 'no-repeat',
    },
    attachment: undefined,
    origin: undefined,
    clip: undefined
}

Chained call

Make sure props of declarations related to same shorthand.

import Fruit from 'css-fruit';
const background = Fruit
    .absorb('background', 'url(abc.png) #eee repeat-x')
    .absorb('background-size', '100%')
    .absorb('background-position', 'top right');

Decl or Array

An object like postcss decl struct is allowed:

import Fruit from 'css-fruit';
const background = Fruit
    .absorb({ prop: 'background', value: 'url(abc.png) #eee repeat-x' })
    .absorb({ prop: 'background-size', value: '100%' })
    .absorb({ prop: 'background-position', value: 'top right' });

You can pass an Array also.

import Fruit from 'css-fruit';
const background = Fruit.absorb([
    { prop: 'background', value: 'url(abc.png) #eee repeat-x' },
    { prop: 'background-size', value: '100%' },
    { prop: 'background-position', value: 'top right' }
]);

import as required

If you want process CSS properties only about background in your project, it is better to import as required.

import { Background } from 'css-fruit';

const background = Background
    .absorb('background', 'url(abc.png) #eee repeat-x')
    .absorb('background-size', '100%')
    .absorb('background-position', 'top right');

Develop

build

npm run build

test

npm run test

Changelog

See Releases

Contributing

See Contributing Guide

License

MIT

Keywords

FAQs

Last updated on 17 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc