Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sass-variable-loader

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

sass-variable-loader - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

7

dist/get-variables.js

@@ -7,7 +7,10 @@ 'use strict';

exports.default = getVariables;
// strip-css-comments only handles multiline comments but sass allows single-line
// style as well. strip-json-comments handles both
var stripComments = require('strip-json-comments');
function getVariables(content) {
var variableRegex = /\$(.+):\s+(.+);/;
var variables = [];
content.split('\n').forEach(function (line) {
stripComments(content).split('\n').forEach(function (line) {
var variable = variableRegex.exec(line);

@@ -14,0 +17,0 @@ if (!variable) return;

'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.default = parseVariables;

@@ -9,0 +10,0 @@

{
"name": "sass-variable-loader",
"version": "0.0.3",
"version": "0.0.4",
"description": "Sass variable loader module for webpack",

@@ -34,3 +34,4 @@ "main": "dist/index.js",

"lodash": "^3.10.1",
"node-sass": "^3.4.2"
"node-sass": "^3.4.2",
"strip-json-comments": "^2.0.1"
},

@@ -37,0 +38,0 @@ "devDependencies": {

@@ -0,6 +1,9 @@

// strip-css-comments only handles multiline comments but sass allows single-line
// style as well. strip-json-comments handles both
const stripComments = require('strip-json-comments');
export default function getVariables(content) {
const variableRegex = /\$(.+):\s+(.+);/;
const variables = [];
content.split('\n').forEach(line => {
stripComments(content).split('\n').forEach(line => {
const variable = variableRegex.exec(line);

@@ -7,0 +10,0 @@ if (!variable) return;

@@ -5,26 +5,55 @@ import { expect } from 'chai';

const sass = '$gray-base: #000 !default;\n$gray-darker: lighten($gray-base, 13.5%) !default; // #222\n$gray-dark: lighten($gray-base, 20%) !default; // #333\n$gray: lighten($gray-base, 33.5%) !default; // #555\n$gray-light: lighten($gray-base, 46.7%) !default; // #777\n$gray-lighter: lighten($gray-base, 93.5%) !default; // #eee';
const variables = getVariables(sass);
context('without comments', function() {
const sass = '$gray-base: #000 !default;\n$gray-darker: lighten($gray-base, 13.5%) !default; // #222\n$gray-dark: lighten($gray-base, 20%) !default; // #333\n$gray: lighten($gray-base, 33.5%) !default; // #555\n$gray-light: lighten($gray-base, 46.7%) !default; // #777\n$gray-lighter: lighten($gray-base, 93.5%) !default; // #eee';
const variables = getVariables(sass);
describe('getVariables()', function() {
it('should return an array with 6 items', function() {
expect(variables).to.be.a('array');
expect(variables).to.have.length(6);
});
});
describe('getVariables()', function() {
it('should return an array with 6 items', function() {
expect(variables).to.be.a('array');
expect(variables).to.have.length(6);
});
});
describe('parseVariables()', function() {
it('should return an object with the key grayBase', function() {
const result = parseVariables(variables);
expect(result).to.be.a('object');
expect(result).to.include.keys('grayBase');
});
});
describe('parseVariables()', function() {
it('should return an object with the key grayBase', function() {
const result = parseVariables(variables);
expect(result).to.be.a('object');
expect(result).to.include.keys('grayBase');
});
});
describe('parseVariables({ preserveVariableNames: true })', function() {
it('should return an object with the key gray-base', function() {
const result = parseVariables(variables, { preserveVariableNames: true });
expect(result).to.be.a('object');
expect(result).to.include.keys('gray-base');
});
});
describe('parseVariables({ preserveVariableNames: true })', function() {
it('should return an object with the key gray-base', function() {
const result = parseVariables(variables, { preserveVariableNames: true });
expect(result).to.be.a('object');
expect(result).to.include.keys('gray-base');
});
});
})
context('with comments', function() {
const sass = `$one: 123;
$x: $one;
// $y: $two; // ERROR - $two not existed, but it's commented`
const variables = getVariables(sass);
describe('getVariables()', function() {
it('should return an array with 2 items', function() {
expect(variables).to.be.a('array');
expect(variables).to.have.length(2);
});
});
describe('parseVariables()', function() {
it('should return an object with the key one', function() {
const result = parseVariables(variables);
expect(result).to.be.a('object');
expect(result).to.include.keys('one');
});
it('should not return an object with the key y', function() {
const result = parseVariables(variables);
expect(result).to.be.a('object');
expect(result).to.not.include.keys('y');
});
});
})
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