less-vars-to-js
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -10,3 +10,3 @@ 'use strict'; | ||
sheet.match(/@(.[^;]*)/g).forEach(function (variable) { | ||
sheet.match(/@(.*:[^;]*)/g).forEach(function (variable) { | ||
if (variable.indexOf('@import') === 0) { | ||
@@ -13,0 +13,0 @@ return; |
{ | ||
"name": "less-vars-to-js", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Read LESS variables from the contents of a file and returning them as a javascript object.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,3 +5,3 @@ [![Build Status](https://img.shields.io/travis/mjt01/less-vars-to-js/master.svg?style=flat-square)](https://travis-ci.org/mjt01/less-vars-to-js) | ||
# less-vars-to-js | ||
Read [LESS](http://lesscss.org/) variables from the contents of a file and returning them as a javascript object. | ||
Read [LESS](http://lesscss.org/) variables from the contents of a file and return them as a javascript object. | ||
```js | ||
@@ -14,2 +14,38 @@ $ npm install --save less-vars-to-js | ||
### What does it do? | ||
Takes in the contents of a less file as a `string` and returns an `object` containing all the variables it found. It is deliberately naive as it is not intending to be a less parser. Basically it reads anything starting with an `@`, so it will ignore comments, rule definitions, import statements etc. | ||
Example : | ||
```less | ||
@import (reference) "theme"; | ||
// Colour palette | ||
@blue: #0d3880; | ||
@pink: #e60278; | ||
// Elements | ||
@background: @gray; | ||
@favourite: blanchedalmond; | ||
// Grid | ||
@row-height: 9; | ||
.element { | ||
@foreground: black; | ||
color: @foreground; | ||
} | ||
``` | ||
Example output: | ||
```js | ||
{ | ||
'@blue': '#0d3880', | ||
'@pink': '#e60278', | ||
'@background': '@gray', | ||
'@favourite': 'blanchedalmond', | ||
'@row-height': 9, | ||
'@foreground': 'black' | ||
} | ||
``` | ||
**Note:** while it does return variables it finds within rules, it is recommended to use this on files containing only variables, as it's not a parser and is designed to extract design principles for style guides. | ||
### Usage | ||
@@ -16,0 +52,0 @@ ```js |
@@ -66,2 +66,40 @@ import lessVarsToJS from '../src'; | ||
} | ||
}, | ||
{ | ||
should: 'should ignore rules', | ||
input: ` | ||
@import (reference) 'theme'; | ||
@blue: #0d3880; | ||
.element { | ||
color: @foreground; | ||
} | ||
@pink: #e60278; | ||
`, | ||
output: { | ||
'@blue': '#0d3880', | ||
'@pink': '#e60278' | ||
} | ||
}, | ||
{ | ||
should: 'should ignore include variables from within', | ||
input: ` | ||
@import (reference) 'theme'; | ||
@blue: #0d3880; | ||
.element { | ||
@foreground: black; | ||
color: @foreground; | ||
} | ||
@pink: #e60278; | ||
`, | ||
output: { | ||
'@blue': '#0d3880', | ||
'@foreground': 'black', | ||
'@pink': '#e60278' | ||
} | ||
} | ||
@@ -68,0 +106,0 @@ ]; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45175
700
83