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

lexeme

v0.0.1

Published

A lexical analyzer that turns CSS into parser friendly tokens.

Downloads

2

Readme

  /LL
| LL
| LL         /eeeeee   /xx   /xx   /eeeeee   /mmmmmm/mmmm    /eeeeee
| LL        /ee__  ee |  xx /xx/  /ee__  ee | mm_  mm_  mm  /ee__  ee
| LL       | eeeeeeee  \  xxxx/  | eeeeeeee | mm \ mm \ mm | eeeeeeee
| LL       | ee_____/   >xx  xx  | ee_____/ | mm | mm | mm | ee_____/
| LLLLLLLL |  eeeeeee  /xx/\  xx |  eeeeeee | mm | mm | mm |  eeeeeee
|________/  \_______/ |__/  \__/  \_______/ |__/ |__/ |__/  \_______/

Lexeme is a lexical analyzer that turns CSS into parser friendly tokens.

Install

Install Lexeme from npm:

npm install lexeme

Or with yarn:

yarn add lexeme

Then require it into any module:

const { tokenize } = require('lexeme');

Tokens

A single token is represented as an Array with the following shape:

[
  // The token type, for example `BRACE_OPEN`
  type{String},

  // The value of the token, for example `{`
  value{String},

  // The position of the string being tokenized, for example [1,10]
  location{Array<line<number>, column<?number>}
]

Token Types

| Type | Example | | --- |---| | BRACE_OPEN | { | | BRACE_CLOSE | } | | MEDIA_QUERY | @media (min-width: 300px) | | KEYFRAME | @keyframes slide | | KEYFRAME_SELECTOR | from | to | 0-100% | | FONT_FACE | @font-face | | CHARSET | @charset | | SUPPORTS | @supports | | DECLARATION | display: flex; | | SELECTOR | nav | span.icon | h1, h2, h3 |

Note: Inline and multi-line comments in CSS are ignored.

API

tokenize

tokenize(CSS)
  • Description:

    Transforms CSS into tokens.

  • Parameters:

    • CSS{String}: The CSS source code.
  • Returns:

    An interface to query tokens:

    {
      tokens: ƒ tokens()
      selectors: ƒ selectors()
      declarations: ƒ declarations()
      mediaQueries: ƒ mediaQueries()
      rulesets: ƒ rulesets()
      rulesetsAsObjects: ƒ rulesetsAsObjects()
    }

.tokens()

tokenize(CSS).tokens();
  • Returns:

    An Array containing all tokens.

.selectors()

tokenize(CSS).selectors();
  • Returns:

    An Array containing tokens of the type SELECTOR.

.declarations()

tokenize(CSS).declarations();
  • Returns:

    An Array containing tokens of the type DECLARATION.

.mediaQueries()

tokenize(CSS).mediaQueries();
  • Returns:

    An Array containing tokens of the type MEDIA_QUERY.

.rulesets()

tokenize(CSS).rulesets();
  • Returns:

    An Array containing a Map for each ruleset:

    [
      Map {
        selector{String},
        declarations{Array<String>}
      },
      Map {
        ...
      }
    ]

.rulesetsAsObjects()

tokenize(CSS).rulesetsAsObjects();
  • Returns:

    An Array containing an Object for each ruleset:

    [
      {
        selector{String},
        declarations{Array<String>}
      },
      {
        ...
      }
    ]

Tests

Run all tests with:

npm test

Or run a specific test with:

npm test tokens

Licence

MIT

Copyright (c) 2018-present, Callum Hart