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

myth

v1.5.0

Published

A CSS preprocessor that acts like a polyfill for future versions of the spec.

Downloads

6,258

Readme

Myth Build Status

CSS the way it was imagined.

Myth is a preprocessor that lets you write pure CSS without having to worry about slow browser support, or even slow spec approval. It's like a CSS polyfill.

Installation

$ npm install -g myth

Usage

$ myth input.css output.css
# Generated output.css from input.css

Community

Why?

Myth lets you write pure CSS while still giving you the benefits of tools like LESS and Sass. You can still use variables and math functions, just like you do in preprocessors. It's like a polyfill for future versions of the spec.

Some of the features in CSS require runtime calculations, which neither Myth nor preprocessors handle, but what Myth does is let you write your code today in the future syntax, so that your code is future-proof. When browsers finally support these features you won't need to rewrite anything, just start using the cascade!

Taking plain CSS as an input also means you can use Myth to re-process anyone else's CSS (or another preprocessors output), adding the browser support you need, without having to re-write the code in a completely different syntax.

Myth is built with Rework so it's incredibly fast, and has a nice Javascript API in addition to the CLI.

Example

An example is the easiest way to explain it. If you write spec-compliant CSS:

:root {
  --green: #a6c776;
}

@custom-media --narrow-window screen and (max-width: 30em);

@media (--narrow-window) {
  html {
    font-size: 1.2rem;
  }
}

a {
  color: var(--green);
  font-variant: all-small-caps;
  transition: color 1s;
}

a:hover {
  color: color(var(--green) shade(20%));
}

::placeholder {
  opacity: .4;
  transition: opacity 1s;
}

:focus::placeholder {
  opacity: .2;
}

... Myth will transform it for you, into browser-compliant CSS:

@media screen and (max-width: 30em) {
  html {
    font-size: 1.2rem;
  }
}

a {
  color: #a6c776;
  -webkit-font-feature-settings: "smcp", "c2sc";
  -moz-font-feature-settings: "smcp", "c2sc";
  font-feature-settings: "smcp", "c2sc";
  font-variant: all-small-caps;
  -webkit-transition: color 1s;
  transition: color 1s;
}

a:hover {
  color: rgb(133, 159, 94);
}

::-webkit-input-placeholder {
  opacity: .4;
  -webkit-transition: opacity 1s;
  transition: opacity 1s;
}

::-moz-placeholder {
  opacity: .4;
  transition: opacity 1s;
}

:-ms-input-placeholder {
  opacity: .4;
  transition: opacity 1s;
}

::placeholder {
  opacity: .4;
  -webkit-transition: opacity 1s;
  transition: opacity 1s;
}

:focus::-webkit-input-placeholder {
  opacity: .2;
}

:focus::-moz-placeholder {
  opacity: .2;
}

:focus:-ms-input-placeholder {
  opacity: .2;
}

:focus::placeholder {
  opacity: .2;
}

Features

Variables

Using the same syntax as the CSS spec. Just like future CSS, but without the cascade. Thanks to rework-vars.

:root {
  --purple: #847AD1;
}

a {
  color: var(--purple);
}

Math

Using the same syntax as the CSS spec. Just like future CSS, but without runtime interpolation. Thanks to rework-calc.

pre {
  margin: calc(50px * 2);
}

Custom media queries

Using the same syntax as the CSS spec. Thanks to rework-custom-media.

@custom-media --narrow-window (max-width: 30em);

@media (--narrow-window) {
  /* narrow window styles */
}

@media (--narrow-window) and (script) {
  /* special styles for when script is allowed */
}

Color Manipulation

Using the same syntax as the CSS spec. Thanks to rework-color-function.

a {
  color: #847AD1;
}

a:hover {
  color: color(#847AD1 tint(20%));
}

No Prefixes

The prefixes from the most-common and most-recent browsers are supported, so you never need to worry about what the current browser support landscape is. Big thanks to autoprefixer!

.button {
  background: linear-gradient(to bottom, black, white);
  transition: transform .25s;
}

And more...

API

Command Line

Usage: myth [<input>] [<output>]

Options:

  -h, --help          output usage information
  -V, --version       output the version number
  -c, --compress      compress output
  -w, --watch         watch the input file for changes
  -s, --sourcemap     add source map
  -v, --verbose       log verbose output for debugging

  --no-import         disable import support
  --no-variables      disable variables support
  --no-custom-media   disable custom media support
  --no-hex-alpha      disable hex alpha support
  --no-color          disable color support
  --no-calc           disable calc support
  --no-font-variant   disable font variant support
  --no-rebeccapurple  disable rebeccapurple support
  --no-prefixes       disable prefixes support

Examples:

  # pass an input and output file:
  $ myth input.css output.css

  # watch the input file for changes:
  $ myth --watch input.css output.css

  # unix-style piping to stdin and stdout:
  $ cat input.css | myth | grep background-color

Node.js

var myth = require('myth');
var fs = require('fs');

var css = fs.readFileSync('index.css', 'utf8');
var converted = myth(css);

fs.writeFileSync('converted.css', converted);

Or use it directly as a Rework plugin:

var myth = require('myth');
var rework = require('rework');
var fs = require('fs');

var css = fs.readFileSync('index.css', 'utf8');
var converted = rework(css)
  .use(myth())
  .toString();

fs.writeFileSync('converted.css', converted);

Available options:

| Key | Type | Description | ----------- | --------- | ----------- | browsers | Array | An array of browsers and versions to support. | compress | Boolean | Whether to compress the CSS output. | features | Object | A dictionary of features to disable. All features are enabled by default. Available features: calc, color, customMedia, fontVariant, hexAlpha, import, prefixes, rebeccapurple, variables. | preserve | Boolean | Whether to preserve variables in the output. | source | String | The full path to the source CSS file. This is required if you want Myth to concatenate @import rules in your CSS. | sourcemap | Boolean | Whether to embed a source map. | variables | Object | A dictionary of CSS variables to use.

License

The MIT License (MIT)

Copyright (c) 2015, Segment <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.