Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

2letterbem

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

Published28 Apr 2020
Direct dependencies6
Transitive dependenciesNot calculated

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.

Declared dependencies 6

Native requirements
6 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
css
Environment
{
  "local_name": "css",
  "alias": false,
  "peer_metadata": null
}
^2.2.4runtime
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^25.4.0runtime
lodash
Environment
{
  "local_name": "lodash",
  "alias": false,
  "peer_metadata": null
}
^4.17.15runtime
string-extract-class-names
Environment
{
  "local_name": "string-extract-class-names",
  "alias": false,
  "peer_metadata": null
}
^5.9.22runtime
string-permutation
Environment
{
  "local_name": "string-permutation",
  "alias": false,
  "peer_metadata": null
}
^0.1.0runtime
yargs
Environment
{
  "local_name": "yargs",
  "alias": false,
  "peer_metadata": null
}
^15.3.1runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-xdpPhRZGYYUw7geVtHlseWZAkMZqzUiLI2i6s3XKGDENVbCfr1gRZjznxjjHOiluaSKGHRMa8hcGdRcUuozbYA==",
  "shasum": "b794b37196b86e986e2c609eb8aabf234411bec7",
  "tarball": "https://registry.npmjs.org/2letterbem/-/2letterbem-1.0.1.tgz",
  "fileCount": 6,
  "unpackedSize": 9610,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJep4VeCRA9TVsSAnZWagAA84UP/25orQrZoeWQNDlkJA71\nEnDqv63ShxGeYy9d7KCF9XdPlRWRsEdgeDfZhF/6EJcfG2FhD/tnQVKFWk+J\n4li/jKtEx+giymV9SpLBkGL4mQv/q2CIFPoqzljK3RhtREp1y59SeoqajqDq\nQfKBoG3KmP2VYIHbqr1x8cyIZThpzIIj06FjysAPZANdvyNkYTFOSvN75Wy1\nO+CKUc8m3FoSIhHDs5eBjS9CLT4O8VQFTK5BUg49ntHAim69Ne2rgYWXhhov\nIkh0eGWBcxxByK68zfGEzKpTIow1KAo2IdTGhZJ2u7Pi45s37cQ4mM9Wllpq\n/Sz+ZR63NN/igMwT/6ffYjlkqYuYWc0R0BGRUT1JcpPA72SPaThR6TR1KDZz\nxJk8OAuH/MC7ABZGOcp8/kMUpqa8yk0Nr/Hh/ZnLQB9vpvEAuvMTNwAdLAMr\nTYy7mdzY/YLmgYLr/d0aUjiNlIKUn3cLa0JJ2RwtnDjCmawhW13TiaokrGF9\no6neFG3caGsDJfnwr8quG9Y35SpLBxq6PJRbyCJIGNyfpkHUmAGa1/8ZJH4g\nMCKw2++mTIJaZjkMZ9PXx6EPpbbOWPnGgAUiEhwulVuODeXPqWauUVLWvnko\nXdTVpXqGqMQDl1Yp/w8OoWowXrBNq2K2JjBqE4EF8dQHxbrSg+9xU0XAYSX9\n42r5\r\n=eINC\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIF9TikV32DZ2F9nl/V5Ovar3+FU5yz/Bakpn86DN+/K1AiAinOsOBUG0QfsNF37w0df4B/kPTNP32SSB9Cgtl/rZJA=="
    }
  ]
}

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_version:461ab7b1700671c787b68298672dd4b82c7cc7eed3f15ea2e7898206fade05fb

Other collected versions

1.0.328 Apr1.0.228 Apr1.0.028 AprView all collected versions →