From 0e84a31ff2223c15f0a7b5bc939e3a87a514174f Mon Sep 17 00:00:00 2001 From: Puneet Goyal Date: Thu, 26 Oct 2017 23:02:57 +0530 Subject: [PATCH 1/2] minor fix --- src/app/converter/converter.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/converter/converter.test.ts b/src/app/converter/converter.test.ts index c473cd7..670f5fc 100644 --- a/src/app/converter/converter.test.ts +++ b/src/app/converter/converter.test.ts @@ -6,7 +6,7 @@ import { Utils } from '../utils'; describe('Converter class', () => { let options = { inputFiles: [''], format: 'JSON' }; - it('should return an instance of Converer', () => { + it('should return an instance of Converter', () => { let converter = new Converter(options); expect(converter).to.be.instanceof(Converter); }); @@ -24,7 +24,7 @@ describe('Converter class', () => { }); - describe('JSON exported extructure', () => { + describe('JSON exported structure', () => { let opts = { inputFiles: [path.resolve('./test/scss/_variables.scss')], format: 'JSON' }; let converter = null; let results = null; From b641ac884b3117a2b91489cab7ad0cd94df6c5d0 Mon Sep 17 00:00:00 2001 From: Puneet Goyal Date: Thu, 26 Oct 2017 23:04:37 +0530 Subject: [PATCH 2/2] rename 'variable' to 'name' --- src/app/converter/converter.test.ts | 6 +++--- src/app/converter/converter.ts | 4 ++-- src/app/parser/parser.test.ts | 12 ++++++------ src/app/parser/parser.ts | 4 ++-- src/app/utils/utils.test.ts | 8 ++++---- src/app/utils/utils.ts | 4 ++-- src/libs/globals.d.ts | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/app/converter/converter.test.ts b/src/app/converter/converter.test.ts index 670f5fc..e62898c 100644 --- a/src/app/converter/converter.test.ts +++ b/src/app/converter/converter.test.ts @@ -42,13 +42,13 @@ describe('Converter class', () => { }); it('should have the correct object structure', () => { - expect(results[0]).to.have.property('variable'); + expect(results[0]).to.have.property('name'); expect(results[0]).to.have.property('value'); expect(results[0]).to.have.property('compiledValue'); }); it('should have the variable the same as the sass file', () => { - expect(results[0].variable).to.equal('$white'); + expect(results[0].name).to.equal('$white'); expect(results[0].value).to.equal('#fff'); expect(results[0].compiledValue).to.equal('#fff'); }); @@ -172,7 +172,7 @@ describe('Converter class', () => { let structured = converter.getStructured(); expect(structured.icons[0]).to.have.property('mapValue'); - expect(structured.icons[0].mapValue[0].variable).to.be.equal('glass'); + expect(structured.icons[0].mapValue[0].name).to.be.equal('glass'); expect(structured.icons[0].mapValue[0].value).to.be.equal('value'); expect(structured.icons[0].mapValue[0].compiledValue).to.be.equal('value'); }); diff --git a/src/app/converter/converter.ts b/src/app/converter/converter.ts index 42d9fb7..af43317 100644 --- a/src/app/converter/converter.ts +++ b/src/app/converter/converter.ts @@ -22,7 +22,7 @@ export class Converter { return parsedDeclarations.map((declaration) => { declaration.compiledValue = this.renderPropertyValue(content, declaration); - declaration.variable = `$${declaration.variable}`; + declaration.name = `$${declaration.name}`; if (declaration.mapValue) { declaration.mapValue.map((mapDeclaration) => { @@ -52,7 +52,7 @@ export class Converter { let compiledGroup = structuredDeclaration[group].map((declaration) => { declaration.compiledValue = this.renderPropertyValue(content, declaration); - declaration.variable = `$${declaration.variable}`; + declaration.name = `$${declaration.name}`; if (declaration.mapValue) { declaration.mapValue.map((mapDeclaration) => { diff --git a/src/app/parser/parser.test.ts b/src/app/parser/parser.test.ts index 107437a..f08189f 100644 --- a/src/app/parser/parser.test.ts +++ b/src/app/parser/parser.test.ts @@ -26,7 +26,7 @@ describe('Parser class', () => { expect(validParser.parse()).that.is.an('array'); expect(validParser.parse()).to.have.lengthOf(1); - expect(validParser.parse()[0].variable).to.be.equal('slate-dark'); + expect(validParser.parse()[0].name).to.be.equal('slate-dark'); expect(validParser.parse()[0].value).to.be.equal('#4f6f7b'); }); @@ -74,7 +74,7 @@ describe('Parser class', () => { expect(structured).to.have.property('theme-colors'); expect(structured.globals.length).be.equal(2); expect(structured['theme-colors'].length).be.equal(3); - expect(structured['theme-colors'][1].variable).to.be.equal('brand-gray-medium'); + expect(structured['theme-colors'][1].name).to.be.equal('brand-gray-medium'); }); it('should group in globals if end-section is present', () => { @@ -91,7 +91,7 @@ describe('Parser class', () => { expect(structured).to.have.property('light'); expect(structured.globals.length).be.equal(4); expect(structured.light.length).be.equal(1); - expect(structured.light[0].variable).be.equal('brand-gray-light'); + expect(structured.light[0].name).be.equal('brand-gray-light'); }); it('should ignore the section if the name is invalid', () => { @@ -136,7 +136,7 @@ describe('Parser class', () => { let structured = parser.parseStructured(); expect(structured.first.length).be.equal(3); - expect(structured.first[2].variable).be.equal('brand-gray-3'); + expect(structured.first[2].name).be.equal('brand-gray-3'); }); }); @@ -164,7 +164,7 @@ describe('Parser class', () => { let parser = new Parser(content); let structured = parser.parseStructured(); - expect(structured.globals[0].mapValue[0].variable).be.equal('small'); + expect(structured.globals[0].mapValue[0].name).be.equal('small'); expect(structured.globals[0].mapValue[0].value).be.equal('767px'); expect(structured.globals[0].mapValue[1].value).be.equal('$bp-medium'); @@ -180,7 +180,7 @@ describe('Parser class', () => { let parser = new Parser(content); let parsedArray = parser.parse(); - expect(parsedArray[0].mapValue[0].variable).be.equal('small'); + expect(parsedArray[0].mapValue[0].name).be.equal('small'); expect(parsedArray[0].mapValue[0].value).be.equal('767px'); expect(parsedArray[0].mapValue[1].value).be.equal('$bp-medium'); diff --git a/src/app/parser/parser.ts b/src/app/parser/parser.ts index 43f3dec..25bbd87 100644 --- a/src/app/parser/parser.ts +++ b/src/app/parser/parser.ts @@ -127,10 +127,10 @@ export class Parser { return; } - let variable = matches[1].trim().replace('_', '-'); + let name = matches[1].trim().replace('_', '-'); let value = matches[2].trim().replace(/\s*\n+\s*|\"/g, ''); - return { variable, value } as IDeclaration; + return { name, value } as IDeclaration; } diff --git a/src/app/utils/utils.test.ts b/src/app/utils/utils.test.ts index 251d874..0d8c3d9 100644 --- a/src/app/utils/utils.test.ts +++ b/src/app/utils/utils.test.ts @@ -5,9 +5,9 @@ describe('Utils class', () => { let declarations = [ // tslint:disable:object-literal-key-quotes - { "variable": "$brand-blue-gray", "value": "#647b86", "compiledValue": "#647b86" }, - { "variable": "$brand-blue-gray-dark", "value": "#546E7A", "compiledValue": "#546E7A" }, - { "variable": "$brand-solitude", "value": "#ebeff2", "compiledValue": "#ebeff2" } + { "name": "$brand-blue-gray", "value": "#647b86", "compiledValue": "#647b86" }, + { "name": "$brand-blue-gray-dark", "value": "#546E7A", "compiledValue": "#546E7A" }, + { "name": "$brand-solitude", "value": "#ebeff2", "compiledValue": "#ebeff2" } ]; it('should have a public helper getDeclaration', () => { @@ -32,7 +32,7 @@ describe('Utils class', () => { }); it('should wrap a variable', () => { - let declaration = { variable: 'var', value: '$the-value', compiledValue: '' }; + let declaration = { name: 'var', value: '$the-value', compiledValue: '' }; let expectedResult = '#sass-export-id.var{content:"#{$the-value}";}'; let wrapped = Utils.wrapCss(declaration); diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index 20d65c3..49eaeab 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -9,14 +9,14 @@ const UNWRAPPER_PATTERN = `${WRAPPER_CSS_ID}\\.(.+)\\s*\\{\\s*content:\\s*["'](. export class Utils { public static getDeclarationByName(declarations: IDeclaration[] = [], name: string): IDeclaration { - let filtered = declarations.filter((declaration) => declaration.variable === name); + let filtered = declarations.filter((declaration) => declaration.name === name); return filtered[0]; } public static wrapCss(cssDeclaration: IDeclaration): string { - return `${WRAPPER_CSS_ID}.${cssDeclaration.variable}{content:"#{${cssDeclaration.value}}";}`; + return `${WRAPPER_CSS_ID}.${cssDeclaration.name}{content:"#{${cssDeclaration.value}}";}`; } diff --git a/src/libs/globals.d.ts b/src/libs/globals.d.ts index 3a89bf5..7f7f0d2 100644 --- a/src/libs/globals.d.ts +++ b/src/libs/globals.d.ts @@ -6,7 +6,7 @@ interface IOptions { } interface IDeclaration { - variable: string, + name: string, value: string, mapValue?: Array, compiledValue: string