Socket
Socket
Sign inDemoInstall

lessvars

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lessvars

Parses LESS-files and extracts variables


Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

lessvars

Read LESS variables from a less-file and return all variables as a javascript object.

$ npm install --save lessvars

How does it work?

This library uses the less-library to parse the less-file into an AST. The AST is then walked in order to find all variables, this includes variables defined in imported files and where color-functions has been used.

Example

// toBeImported.less
@fromAnImport: blue;

// index.less
@import "tobeImported";

@minVar1: blue;
@minVar2: #f00;
@minVar3: #f0ff00;
@minVar4: rgb(124, 124, 124);
@minVar5: rgba(124, 124, 124, 0.5);
@minVar6: hsl(120, 100%, 50%);
@minVar7: hsla(120, 100%, 50%, 0.75);
@minVar8: #ffffff;

@compondVar1: lighten(@minVar5, 20%);
@compondVar2: darken(@minVar6, 20%);
@compondVar3: mix(@minVar1, @minVar2, 50%);



@notACOlor: 3%;
@not2ACOlor: 3;
@hsv: hsv(120, 100%, 100%);

.test {
  @includeThis: blue;
}

Example output:

{
  "fromAnImport": "blue",
  "minVar1": "blue",
  "minVar2": "#f00",
  "minVar3": "#f0ff00",
  "minVar4": "#7c7c7c",
  "minVar5": "rgba(124, 124, 124, 0.5)",
  "minVar6": "#00ff00",
  "minVar7": "rgba(0, 255, 0, 0.75)",
  "minVar8": "#ffffff",
  "compondVar1": "rgba(175, 175, 175, 0.5)",
  "compondVar2": "#009900",
  "compondVar3": "#800080",
  "notACOlor": "3%",
  "not2ACOlor": "3",
  "hsv": "#00ff00",
  "includeThis": "blue"
}

NOTE: As seen by the example, it returns variables defined in imported files, within rules and resolves darken, lighten etc.

Usage

import fs from 'fs';
import lessvars from 'lessvars';

const content = fs.readFileSync('./index.less', 'utf-8');

function printObject(obj) {
    Object.entries(obj)
        .forEach(([key, value]) => console.log(key, value));
}

// Use with callback
lessvars(content, (err, variables) => {
    printObject(variables);
});

// Use with promise
lessvars(content)
    .then(printObject);

Lisence

X11 (This license is identical to the MIT License, but with an extra sentence that prohibits using the copyright holders' names for advertising or promotional purposes without written permission. )

FAQs

Package last updated on 12 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc