Skip to content

Commit

Permalink
lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
cancerberoSgx committed Nov 15, 2018
1 parent 9fc0cf9 commit 3ff1e01
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 228 deletions.
8 changes: 4 additions & 4 deletions spec/executionContextSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
20 changes: 9 additions & 11 deletions spec/formatSpec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
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

beforeAll(() => {
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 => {
Expand All @@ -38,9 +37,9 @@ export default describe('formats', () => {
})
done()
})

it('info format should match', async done => {

const mimeTypes = {
jpg: 'image/jpeg',
png: 'image/png',
Expand Down Expand Up @@ -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')
Expand All @@ -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` })
Expand Down
1 change: 0 additions & 1 deletion spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ export * from './util/fileSpec'
export * from './util/imageBuiltInSpec'
export * from './util/imageCompareSpec'
export * from './util/imageExtractInfoSpec'

4 changes: 2 additions & 2 deletions spec/util/imageBuiltInSpec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {

Expand Down
5 changes: 3 additions & 2 deletions spec/util/imageCompareSpec.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion spec/util/imageExtractInfoSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildInputFile, extractInfo } from '../../src';
import { buildInputFile, extractInfo } from '../../src'

export default describe('util/imageExtractInfo', () => {

Expand Down
14 changes: 7 additions & 7 deletions src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecuteResult> {
Expand Down
18 changes: 8 additions & 10 deletions src/executionContext.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,7 +13,6 @@ export interface ExecutionContext {
getFile(name: string): Promise<MagickInputFile>
}


class ExecutionContextImpl implements ExecutionContext {

private builtInImages: MagickInputFile[] = []
Expand All @@ -39,17 +38,16 @@ class ExecutionContextImpl implements ExecutionContext {
}

async getAllFiles(): Promise<MagickInputFile[]> {
const all= await this.imageHome.getAll()
const all = await this.imageHome.getAll()
return all.concat(this.builtInImages)
}

async getFile(name: string): Promise<MagickInputFile> {
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=>{
Expand All @@ -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')
Expand All @@ -82,4 +80,4 @@ function asConfig(configOrCommands: ExecuteConfig|ExecuteCommand|string): Execut

export function newExecutionContext(inheritFrom?: ExecutionContext): ExecutionContext {
return ExecutionContextImpl.create(inheritFrom)
}
}
4 changes: 2 additions & 2 deletions src/util/html.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/util/imageBuiltIn.ts
Original file line number Diff line number Diff line change
@@ -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<MagickInputFile[]> {
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])
})
Expand Down
7 changes: 4 additions & 3 deletions src/util/imageCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 3ff1e01

Please sign in to comment.