From 3ff1e01e364b6e92164c8e84632f5fde833ad8c0 Mon Sep 17 00:00:00 2001 From: Sebastian Gurin Date: Wed, 14 Nov 2018 22:14:59 -0300 Subject: [PATCH] lint code --- spec/executionContextSpec.ts | 8 +- spec/formatSpec.ts | 20 ++- spec/index.ts | 1 - spec/util/imageBuiltInSpec.ts | 4 +- spec/util/imageCompareSpec.ts | 5 +- spec/util/imageExtractInfoSpec.ts | 2 +- src/execute.ts | 14 +- src/executionContext.ts | 18 +-- src/util/html.ts | 4 +- src/util/imageBuiltIn.ts | 10 +- src/util/imageCompare.ts | 7 +- src/util/imageExtractInfo.ts | 251 +++++++++++++++--------------- src/util/index.ts | 2 +- src/util/support.ts | 5 +- tslint.json | 128 +++++++++------ 15 files changed, 251 insertions(+), 228 deletions(-) diff --git a/spec/executionContextSpec.ts b/spec/executionContextSpec.ts index 1a376f0..dfa0096 100644 --- a/spec/executionContextSpec.ts +++ b/spec/executionContextSpec.ts @@ -80,13 +80,13 @@ export default describe('executionContext', () => { done() }) - it('should addBuiltInImages()', async done =>{ + it('should addBuiltInImages()', async done => { let all = await context.getAllFiles() - expect(all.find(i=>i.name==='rose:')).toBeUndefined() + expect(all.find(i => i.name === 'rose:')).toBeUndefined() const builtIn = await context.addBuiltInImages() - expect(builtIn.find(i=>i.name==='rose:')).toBeDefined() + expect(builtIn.find(i => i.name === 'rose:')).toBeDefined() all = await context.getAllFiles() - expect(all.find(i=>i.name==='rose:')).toBeDefined() + expect(all.find(i => i.name === 'rose:')).toBeDefined() done() }) }) diff --git a/spec/formatSpec.ts b/spec/formatSpec.ts index 9b37283..e86e7be 100644 --- a/spec/formatSpec.ts +++ b/spec/formatSpec.ts @@ -1,15 +1,14 @@ import pmap from 'p-map' import { buildInputFile, compare, execute, executeOne, extractInfo, knownSupportedReadWriteImageFormats } from '../src' - export default describe('formats', () => { const formats = knownSupportedReadWriteImageFormats const descriptions = { - psd: 'Adobe Photoshop bitmap file' + psd: 'Adobe Photoshop bitmap file', } - describe('compare and assert on info', ()=>{ + describe('compare and assert on info', () => { let jasmineTimeout @@ -17,11 +16,11 @@ export default describe('formats', () => { jasmineTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000 }) - + afterAll(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineTimeout }) - + it('compare should be true for all combinations', async done => { const compares = [] formats.forEach(f1 => { @@ -38,9 +37,9 @@ export default describe('formats', () => { }) done() }) - + it('info format should match', async done => { - + const mimeTypes = { jpg: 'image/jpeg', png: 'image/png', @@ -68,11 +67,10 @@ export default describe('formats', () => { }) done() }) - - }) + }) - describe('particular formats not supported or working', ()=>{ + describe('particular formats not supported or working', () => { it('svg is not supported', async done => { const img = await buildInputFile('react.svg') @@ -82,7 +80,7 @@ export default describe('formats', () => { expect(errors.length).toBeGreaterThan(0) done() }) - + it('djvu doesn\'t work even read only', async done => { const img = await buildInputFile('formats/to_rotate.djvu') const { outputFiles, errors } = await executeOne({ inputFiles: [img], commands: `convert to_rotate.djvu out.tiff` }) diff --git a/spec/index.ts b/spec/index.ts index 0cf4c34..8634f33 100644 --- a/spec/index.ts +++ b/spec/index.ts @@ -13,4 +13,3 @@ export * from './util/fileSpec' export * from './util/imageBuiltInSpec' export * from './util/imageCompareSpec' export * from './util/imageExtractInfoSpec' - diff --git a/spec/util/imageBuiltInSpec.ts b/spec/util/imageBuiltInSpec.ts index 2d9bf99..de99326 100644 --- a/spec/util/imageBuiltInSpec.ts +++ b/spec/util/imageBuiltInSpec.ts @@ -1,5 +1,5 @@ -import { getBuiltInImages, builtInImageNames, extractInfo, execute, compare } from '../../src'; -import pMap from 'p-map'; +import { getBuiltInImages, builtInImageNames, extractInfo, execute, compare } from '../../src' +import pMap from 'p-map' export default describe('util/imageBuiltIn', () => { diff --git a/spec/util/imageCompareSpec.ts b/spec/util/imageCompareSpec.ts index 5be3b9c..23dd544 100644 --- a/spec/util/imageCompareSpec.ts +++ b/spec/util/imageCompareSpec.ts @@ -1,10 +1,11 @@ -import { buildInputFile, Call, compare, MagickInputFile, outputFileToInputFile } from '../../src'; +import { buildInputFile, Call, compare, MagickInputFile, outputFileToInputFile } from '../../src' export default describe('util/imageCompare', () => { async function test(img1: MagickInputFile | string, img2: MagickInputFile | string, expectedResult: boolean) { const result = await compare(img1, img2) - expect(result).toBe(expectedResult, `Expected compareImage(${typeof img1 === 'string' ? img1 : img1.name} and ${typeof img2 === 'string' ? img2 : img2.name}) to return ${expectedResult} but returned ${result}`) + expect(result).toBe(expectedResult, + `Expected compareImage(${typeof img1 === 'string' ? img1 : img1.name} and ${typeof img2 === 'string' ? img2 : img2.name}) to return ${expectedResult} but returned ${result}`) } it('should return true if image is the same', async done => { diff --git a/spec/util/imageExtractInfoSpec.ts b/spec/util/imageExtractInfoSpec.ts index 9af37b4..ed30678 100644 --- a/spec/util/imageExtractInfoSpec.ts +++ b/spec/util/imageExtractInfoSpec.ts @@ -1,4 +1,4 @@ -import { buildInputFile, extractInfo } from '../../src'; +import { buildInputFile, extractInfo } from '../../src' export default describe('util/imageExtractInfo', () => { diff --git a/src/execute.ts b/src/execute.ts index c48255b..7ccbec0 100644 --- a/src/execute.ts +++ b/src/execute.ts @@ -65,22 +65,22 @@ export function addExecuteListener(l: ExecuteListener) { * ``` * * An alternative syntax with CLI-like strings is also supported: - * + * * ```ts * const {outputFiles} = await execute({inputFiles: [], commands: [ * 'convert rose: -rotate 70 image2.gif', * 'convert image2.gif -resize 33 image3.gif' * ] }) * ``` - * - * Or if it's only one command using just a string: - * + * + * Or if it's only one command using just a string: + * * ```ts * const {outputFiles} = await execute({inputFiles: [foo], commands: `convert 'my face image.png' \\( +clone -channel R -fx B \\) +swap -channel B -fx v.R bar.gif`}) * ``` - * - * Note: in string syntax you must use single quotes for CLI arguments that need so (like 'my face image.png'). no multiline with \ is supported. - * + * + * Note: in string syntax you must use single quotes for CLI arguments that need so (like 'my face image.png'). no multiline with \ is supported. + * * ``` */ export async function execute(config: ExecuteConfig): Promise { diff --git a/src/executionContext.ts b/src/executionContext.ts index ab713e5..a3f7d81 100644 --- a/src/executionContext.ts +++ b/src/executionContext.ts @@ -1,6 +1,6 @@ import { ImageHome, ExecuteConfig, ExecuteResult, execute, ExecuteCommand, createImageHome, MagickInputFile, MagickFile, extractInfo } from '.' -import pMap from 'p-map'; -import { asOutputFile, asInputFile, getBuiltInImages } from './util'; +import pMap from 'p-map' +import { asOutputFile, asInputFile, getBuiltInImages } from './util' /** * Allow multiple execute() calls remembering previus execute() generated output files and previous given input files that can be used as input files in next calls. @@ -13,7 +13,6 @@ export interface ExecutionContext { getFile(name: string): Promise } - class ExecutionContextImpl implements ExecutionContext { private builtInImages: MagickInputFile[] = [] @@ -39,17 +38,16 @@ class ExecutionContextImpl implements ExecutionContext { } async getAllFiles(): Promise { - const all= await this.imageHome.getAll() + const all = await this.imageHome.getAll() return all.concat(this.builtInImages) } async getFile(name: string): Promise { - return (await this.imageHome.get(name)) || this.builtInImages.find(i=>i.name===name) + return (await this.imageHome.get(name)) || this.builtInImages.find(i => i.name === name) } - async addBuiltInImages() { - if(!this.builtInImages.length){ + if (!this.builtInImages.length) { this.builtInImages = await getBuiltInImages() // const builtInImages = ['rose:', 'logo:', 'wizard:', 'granite:', 'netscape:'] // this.builtInImages = await pMap(builtInImages, async name=>{ @@ -60,9 +58,9 @@ class ExecutionContextImpl implements ExecutionContext { // return await asInputFile(outputFiles[0]) // }) } - return this.builtInImages + return this.builtInImages } - + static create(inheritFrom?: ExecutionContext) { if (inheritFrom && !(inheritFrom as ExecutionContextImpl).imageHome) { throw new Error('Dont know how to inherith from other ExecutionContext implementation than this one') @@ -82,4 +80,4 @@ function asConfig(configOrCommands: ExecuteConfig|ExecuteCommand|string): Execut export function newExecutionContext(inheritFrom?: ExecutionContext): ExecutionContext { return ExecutionContextImpl.create(inheritFrom) -} \ No newline at end of file +} diff --git a/src/util/html.ts b/src/util/html.ts index cd1eb1d..3895206 100644 --- a/src/util/html.ts +++ b/src/util/html.ts @@ -1,5 +1,5 @@ -import { MagickFile, MagickInputFile } from '../magickApi'; -import { asOutputFile } from './file'; +import { MagickFile, MagickInputFile } from '../magickApi' +import { asOutputFile } from './file' // utilities related to HTML (img) elements diff --git a/src/util/imageBuiltIn.ts b/src/util/imageBuiltIn.ts index 3d6cc01..c26357a 100644 --- a/src/util/imageBuiltIn.ts +++ b/src/util/imageBuiltIn.ts @@ -1,14 +1,14 @@ -import pMap from "p-map"; -import { MagickInputFile, extractInfo , execute, asInputFile} from ".."; +import pMap from 'p-map' +import { MagickInputFile, extractInfo , execute, asInputFile} from '..' let builtInImages: MagickInputFile[] export const builtInImageNames = ['rose:', 'logo:', 'wizard:', 'granite:', 'netscape:'] export async function getBuiltInImages(): Promise { - if(!builtInImages){ - builtInImages = await pMap(builtInImageNames, async name=>{ + if (!builtInImages) { + builtInImages = await pMap(builtInImageNames, async name => { const info = await extractInfo(name) - const {outputFiles} = await execute({commands:`convert ${name} ${`output1.${info[0].image.format.toLowerCase()}`}`} ) + const {outputFiles} = await execute({commands: `convert ${name} ${`output1.${info[0].image.format.toLowerCase()}`}`} ) outputFiles[0].name = name return await asInputFile(outputFiles[0]) }) diff --git a/src/util/imageCompare.ts b/src/util/imageCompare.ts index 2a7088a..7f0a3c8 100644 --- a/src/util/imageCompare.ts +++ b/src/util/imageCompare.ts @@ -6,7 +6,9 @@ export async function compare(img1: MagickFile | string, img2: MagickFile | stri } export async function compareNumber(img1: MagickFile | string, img2: MagickFile | string): Promise { - let name1: string, imgs: MagickInputFile[] = [], name2: string + const imgs: MagickInputFile[] = [] + let name1: string + let name2: string if (typeof img1 !== 'string') { const inputFile = await asInputFile(img1) imgs.push(inputFile) @@ -23,8 +25,7 @@ export async function compareNumber(img1: MagickFile | string, img2: MagickFile else { name2 = img2 } - const result = await Call( - imgs, + const result = await Call(imgs, ['convert', name1, name2, '-resize', '256x256^!', '-metric', 'RMSE', '-format', '%[distortion]', '-compare', 'info:info.txt'], ) const n = await blobToString(result[0].blob) diff --git a/src/util/imageExtractInfo.ts b/src/util/imageExtractInfo.ts index aab138b..73e988a 100644 --- a/src/util/imageExtractInfo.ts +++ b/src/util/imageExtractInfo.ts @@ -2,13 +2,14 @@ import { asInputFile, Call, MagickFile, blobToString, MagickInputFile } from '.. /** * Execute `convert $IMG info.json` to extract image metadata. Returns the parsed info.json file contents - * + * * TODO: support several input images - we are already returning an array * @param img could be a string in case you want to extract information about built in images like `rose:` */ export async function extractInfo(img: MagickFile|string): Promise { - let name: string, imgs: MagickInputFile[] - if(typeof img !=='string'){ + let name: string + let imgs: MagickInputFile[] + if (typeof img !== 'string') { imgs = [await asInputFile(img)] name = imgs[0].name } @@ -19,197 +20,195 @@ export async function extractInfo(img: MagickFile|string): Promise