Catalog npm
PACKAGE EXPLORERView in registry

2letterbem

npm

Renames css classes to 2 letters to further compress css files.

Versions collected4
Direct dependencies7From release 1.0.3
Last observed20 Oct, 19:14 UTC

README

Current package documentation

2 Letter Bem

Compresses your css classes down to a few characters ( probably 2 ), which you can then use in your html. This is standalone package that is run as a npm script.

Compressing css this way + gzip = negligible results

Example - bootstrap 4.4.1 css minified and gzipped:

  • bootstrap.min.css.gz -> 23.6KB
  • 2 letter bem version -> 22.8KB
  • However, this can be used with html, to shave a kilobyte or two. This could be used to obfuscate your work.

input css file:

.something { ... }
.something__block { ... }
.something__block:hover .that-thing { ... }
.js-action-state something__block.active { ... }

output - creates 2 files css:

.a { ... }
.b { ... }
.b:hover.c { ... }
.js-action-state b.d { ... }

json:

{
"something": "a",
"something__block": "b",
"that-thing": "c",
"active" "d"
}

Anything prepended with .js in your css is not compressed. You can specify a whiteList of classes that you don't want to be touched. They won't appear in the json file either. You can use the json file as dictionary now for your html.

Simple example in PHP:

function klass($cssName){
    $output = [];
    $cssNames = explode(' ', $cssInput);
    foreach ($cssNames as $cssName) {
      if (array_key_exists($cssName, $allYourClassNamesReadFromJSON)) {
        $output[] = $allYourClassNamesReadFromJSON[$cssName];
      } else {
        $output[] = $cssName;
      }
    }
    return implode(' ', $output);
}
<div class="klass('something')"></div> renders as <div class="a"></div>

How to use

In package.json as an example:

{
...
 "config": {
    "2letterbem": {
      "whiteList": [
        ".is-active",
        ".wf-inactive",
      ]
    }
  },
  dependencies: { ... }
  devDependencies: { ... }
  scripts: {
   "2letterbem": "node ./node_modules/2letterbem/2letterbem.js --i ./inputFile.css --o ./outputFile.css --j './jsonMapFile.json"
  }
...

or everything in package.json config

{
  ...
  "config": {
    "2letterbem": {
      "cssPath": "./inputFile.css",
      "jsonSpace": 2,
      "outputCssPath": "./outputFile.css", 
      "outputJsonPath": "./jsonMapFile.json",
      "permutationArgs": {
        "maxSize": 2,
        "recursive": true
      },
      "permutationLetters": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
      "whiteList": [
        ".is-active",
        ".wf-inactive"
      ]
    }
  },
  scripts: {
    "2letterbem": "node ./node_modules/2letterbem/2letterbem.js"
  },
  ...
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 4

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.3Registry latest28 Apr 20207
1.0.228 Apr 20207
1.0.128 Apr 20206
1.0.028 Apr 20206

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
sidouglas/2letterbem

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:14 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:eaaa4165d62b6bf839616ed3bdd49921e7df223bd0ec2e532fff0c2efd4c9db4