From 8bb0a0220b0f64309e4941c17b0ad4d0146feaf4 Mon Sep 17 00:00:00 2001 From: Xymorot Date: Sun, 7 Jun 2020 16:40:32 +0200 Subject: [PATCH] remove: remove class and style utility functions (use Element.classList and HTMLElement.style instead) --- src/renderer/services/utils.spec.ts | 88 +---------------------------- src/renderer/services/utils.ts | 16 ------ 2 files changed, 1 insertion(+), 103 deletions(-) diff --git a/src/renderer/services/utils.spec.ts b/src/renderer/services/utils.spec.ts index e152ff6..03a748f 100644 --- a/src/renderer/services/utils.spec.ts +++ b/src/renderer/services/utils.spec.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; -import fc from 'fast-check'; import 'mocha'; -import { c, s, t } from './utils'; +import { t } from './utils'; describe('Frontend Utils', function () { this.timeout(1000); @@ -9,89 +8,4 @@ describe('Frontend Utils', function () { it("does 'translate' text", () => { expect(t('translate this')).to.equal('translate this'); }); - - describe('Class Util', () => { - beforeEach(function () { - const numeric = fc.integer(0x30, 0x39); - const alphaCapital = fc.integer(0x41, 0x5a); - const alphaSmall = fc.integer(0x61, 0x7a); - const alpha = fc.oneof(alphaCapital, alphaSmall).map(String.fromCharCode); - const alphaNumeric = fc.oneof(numeric, alphaCapital, alphaSmall).map(String.fromCharCode); - - this.className = fc - .stringOf(fc.oneof(alpha, alphaNumeric, fc.constantFrom('-', '_'))) - .filter((name: string) => /[a-zA-Z]/.test(name.charAt(0))); - this.anything = fc - .anything({ - maxDepth: 1, - maxKeys: 2, - }) - .filter((thing) => typeof thing !== 'string'); - }); - - it('compiles classes out of an array', function () { - const classArrayArbitrary = fc.array(fc.oneof(this.className, this.anything)); - - fc.assert( - fc.property(classArrayArbitrary, (classArray) => { - const expectedClasses = classArray.filter((potentialClass) => typeof potentialClass === 'string'); - const compiled = c(classArray); - - expect(compiled).to.be.a('string', 'class util does not return a string'); - expectedClasses.forEach((expectedClassName) => { - expect(compiled).to.contain(expectedClassName, 'class util does not add all classes'); - }); - }) - ); - }); - - it('compiles classes out of an object', function () { - const classObjectArbitrary = fc.object({ - maxDepth: 0, - key: this.className, - values: [fc.boolean()], - }); - - fc.assert( - fc.property(classObjectArbitrary, (classObject: any) => { - const expectedClasses = Object.keys(classObject).filter((key) => classObject[key]); - const compiled = c(classObject); - - expect(compiled).to.be.a('string', 'class util does not return a string'); - expectedClasses.forEach((className) => { - expect(compiled.split(' ')).to.include(className, 'class util does not add all classes'); - }); - }) - ); - }); - }); - - describe('Style Util', () => { - it('compiles an object into an html style property', () => { - const styleObjectArbitrary = fc.object({ - maxDepth: 0, - key: fc.string(1, 10).filter((str) => !/\s/.test(str)), - values: [fc.string(), fc.integer(), fc.boolean()], - }); - - /\s/g.exec(''); - - fc.assert( - fc.property(styleObjectArbitrary, (styleObject: any) => { - const expectedString = Object.keys(styleObject) - .filter((key) => { - const value = styleObject[key]; - if (typeof value === 'string') { - return !!value; - } - return typeof value === 'number'; - }) - .map((key) => `${key}:${styleObject[key]}`) - .join(';'); - - expect(s(styleObject)).to.equal(expectedString); - }) - ); - }); - }); }); diff --git a/src/renderer/services/utils.ts b/src/renderer/services/utils.ts index 30a2c78..d4f5bb1 100644 --- a/src/renderer/services/utils.ts +++ b/src/renderer/services/utils.ts @@ -1,19 +1,3 @@ -export function c(input: Array | object): string { - const array = Array.isArray(input) - ? input.filter((el: any) => typeof el === 'string') - : Object.keys(input).filter((key: keyof object) => !!input[key]); - return array.join(' '); -} - -export function s(styles: object): string { - return Object.keys(styles) - .filter( - (key: keyof object) => typeof styles[key] === 'number' || (typeof styles[key] === 'string' && !!styles[key]) - ) - .map((key: keyof object) => `${key}:${styles[key]}`) - .join(';'); -} - export function t(text: string): string { // If you want to implement frontend translation, begin here. return text;