New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

stylup

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylup

Write utility classes conveniently while optimising your CSS

  • 0.0.0-alpha.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by140%
Maintainers
1
Weekly downloads
 
Created
Source

Stylup pHTML

NPM Version Build Status Support Chat

Stylup gives your markup super powers.

Example

Use to write inteligent functional classes based on their arguments.

<div class="p-4,1,*"></div>

Transforms into styles based on your configuration.

<style>
.80YQhjgv {
  --pt: 4;
  --pr: 1;
  --pl: 1;
}
</style>
<div class="p 80YQhjgv"></div>

You can configure class functions to output whatever you like.

When used with a stylesheet it becomes very powerful, requiring minimal pre configuration to work with your design system.

.p {
  padding-top: calc(var(--pt, initial) * 1rem);
  padding-right: calc(var(--pr, initial) * 1rem);
  padding-bottom: calc(var(--pb, initial) * 1rem);
  padding-left: calc(var(--pl, initial) * 1rem);
}

Features

  • Functional Class Names

    Use inteligent functional class names. Seperate arguments with commas. Use a wildcard to skip arguments. See below for configuring your own class names.

    <div class="p-4 m-*,auto fl-wrap"></div>
    

  • Inline Styles

    Make use of all CSS features inline including hover states and media queries.

    <div style="&:hover { color: red; }"></div>
    

  • Supports PostCSS

    Add support for PostCSS by including a postcss.config.js file in your project.


  • Custom Syntax

    Customise the syntax used for functional classes by by overiding the default regex pattern. stylup.process(html, null, options);

    // Options
    let options = {
      regex: {
        property: /[^-\s]+/,
        number: /[0-9]*\.?[0-9]+|\*/,
        unit: /px|cm|mm|in|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax/,
        seperator: /,/,
        arg: /0*({{number}})({{unit}})?|(\w+)/,
        args: /(?:({{arg}}){{seperator}}?)+/,
        decl: /({{property}})(?:-({{args}}))?/
      	};
    }
    

Configure

By default stylup will look for a file called stylup.config.js at the root of your project.

// phtml-utility-class.config.js
module.exports = {
  classes: [
    {
      class: 'p',
      children: [
        't',
        'r',
        'b',
        'l'
      ],
      style: ({ property, children, args, str }) => {

        if (args.length < 3) args.push(args[0])
        else args.push(args[1])

        for (let [i, side] of children.entries()) {
          str`--${property}${side}: ${args[i]};`
        }

        return str()
      }
    }
    // ...
  ]
}

Usage

Add stylup to your project:

npm install stylup --save-dev

Use stylup to process your HTML:

const stylup = require('stylup');

stylup.process(YOUR_HTML /*, processOptions, pluginOptions */);

Or use it as a pHTML plugin:

const phtml = require('phtml');
const stylup = require('stylup');

phtml([
  stylup(/* pluginOptions */)
]).process(YOUR_HTML /*, processOptions */);

Options

By default block styles are not processed. Set this to true to process them. stylup.process(html, null, options).

// Options
let options = {
  processBlockStyles: true
}

Keywords

FAQs

Package last updated on 02 Sep 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc