npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-scrib

v1.0.1

Published

PostCSS plugin to let you write shortcuts for your favourite properties and their favourite values.

Downloads

9

Readme

PostCSS plugin to let you write shortcuts for your favourite properties and their favourite values.

# my-scrib-shortcuts.txt
b border # Define a property shortcut.
bt border-top
bb border-bottom

d display
  b block # Define a value shortcut by indenting under a property.
  ib inline-block
  tr table-row

c color
bgc background-color
  tr transparent # Value shortcuts work for a group of multiple properties too (seperate groups with double-newlines).

*
  au auto # If necessary, Use * for generic value shortcuts (i.e. not tied to any property).
/* Input.css */
tr.fancy-class {
  b: solid 1px black;
  d: b;
  c: white;
  bgc: tr;
  overflow: au;
}
/* output.css */
tr.fancy-class { /* <-- 'tr' only affects properties, so the selector remains safe */
  border: solid 1px black;
  display: block;
  color: white;
  background-color: transparent;
  overflow: auto;
}

Similar Libraries (may fit your use case better):

  • postcss-alias - Custom aliases for CSS properties through an @alias rule
  • postcss-crip - Useful if you want a pre-defined set of shortcuts

Usage

// Pass a list of shortcuts (formatted like the example on top of this readme) as a string to postcss-scrib
var shortcuts = 'b border\nd display\n  b block';
postcss([require('postcss-scrib')(shortcuts)]);

// OR

// Pass in an options object with with 1 of the following keys: 1) shortcuts, 2) file, or 3) tree.
var options = {
  shortcuts: 'b border\nd display\n  b block', // List of shortcut definitions
  // OR
  file: './my-shortcut-file.txt', // Path to a file that contains shortcut definitions (passed directly to fs.readFile).
  // OR
  tree: {b: 'border', d: 'display', b: 'block'} // Alternative intermediate JS representation.
};
postcss([require('postcss-scrib')(options)]);

See PostCSS docs for examples for your environment.

Intermediate JS representation

Using the tree option, you have the choice of writing your shortcuts directly in JS, instead of in this plugin's custom format. It is slightly more verbose, but may come in useful in cases where you wish to generate shortcuts programmatically, or modify shortcuts at a later time. Converting the example at the top of this readme into a tree gives us:

{ b: 'border',
  bt: 'border-top',
  bb: 'border-bottom',
  d:
   { _becomes: 'display',
     _shortcuts: { b: 'block', ib: 'inline-block', tr: 'table-row' } },
  c: { _becomes: 'color', _shortcuts: { tr: 'transparent' } },
  bgc:
   { _becomes: 'background-color',
     _shortcuts: { tr: 'transparent' } }, // same _shortcuts object reference as c.
  '*': { _becomes: undefined, _shortcuts: { au: 'auto' } } }

parseShortcutText is available as a method on the module if you wish to generate such a tree:

var scrib = require('postcss-scrib');
scrib.parseShortcutText('b border\nd display\n  b block');
// >> {b: 'border', d: 'display', b: 'block'}

Sample Shortcuts

As a reference, here's the shortcuts that I use. I'd suggest to keep the shortcuts tight, and define them only for the props/values you really need (as opposed to going overboard and short-cutting the entire language, then forgetting them all tomorrow morning).

# sneakertack's shortcuts
d display
  b block
  i inline
  ib inline-block
  n none
  t table
  tr table-row
  tc table-cell

pos position
  rel relative
  abs absolute

m margin
mt margin-top
mb margin-bottom
ml margin-left
mr margin-right

b border
bt border-top
bb border-bottom
bl border-left
br border-right

p padding
pt padding-top
pb padding-bottom
pl padding-left
pr padding-right

f font
ff font-family
fs font-size
c color

bg background
bgc background-color

ts text-shadow
bs box-shadow

f float
  l left
  r right