Skip to content

Commit

Permalink
Code style: standard, fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Lcfvs committed May 1, 2018
1 parent 9e19015 commit 0780258
Show file tree
Hide file tree
Showing 190 changed files with 320 additions and 351 deletions.
10 changes: 4 additions & 6 deletions api/blob/blobToBuffer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import { onceLoad } from '../../../dom/emitter/once/onceLoad'
import { global } from '../../../global'
import { promise } from '../../../primitive/function/promise'

const
window = global(),
FileReader = window.FileReader
const window = global()
const FileReader = window.FileReader

export function blobToBuffer (blob) {
return promise(read, blob).then(getTarget)
}

function read (blob, resolve, reject) {
const
reader = new FileReader()
const reader = new FileReader()

reader.readAsArrayBuffer(blob)
onceLoad(reader, resolve)
onceError(reader, reject)
}
}
10 changes: 4 additions & 6 deletions api/blob/blobToDataURL/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ import { global } from '../../../global'
import { curry } from '../../../primitive/function/curry'
import { promise } from '../../../primitive/function/promise'

const
window = global(),
FileReader = window.FileReader
const window = global()
const FileReader = window.FileReader

export function blobToDataURL (blob) {
return promise(read, blob)
}

function read (blob, resolve) {
const
reader = new FileReader()
const reader = new FileReader()

reader.addEventListener('load', curry(onLoad, resolve))
reader.readAsDataURL(blob)
}

function onLoad (resolve, event) {
resolve(event.target.result)
}
}
7 changes: 3 additions & 4 deletions api/blob/blobToImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { global } from '../../../global'
import { dataURLToImage } from '../../dataURL/dataURLToImage'
import { blobToDataURL } from '../blobToDataURL'

const
window = global(),
revokeObjectURL = window.URL.revokeObjectURL
const window = global()
const revokeObjectURL = window.URL.revokeObjectURL

export function blobToImage (blob) {
return blobToDataURL(blob).then(dataURLToImage).then(revoke)
Expand All @@ -14,4 +13,4 @@ function revoke (target) {
revokeObjectURL(target.src)

return target
}
}
10 changes: 4 additions & 6 deletions api/blob/blobToText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import { onceLoad } from '../../../dom/emitter/once/onceLoad'
import { global } from '../../../global'
import { promise } from '../../../primitive/function/promise'

const
window = global(),
FileReader = window.FileReader
const window = global()
const FileReader = window.FileReader

export function blobToText (blob) {
return promise(read, blob).then(getTarget)
}

function read (blob, resolve, reject) {
const
reader = new FileReader()
const reader = new FileReader()

reader.readAsText(blob)
onceLoad(reader, resolve)
onceError(reader, reject)
}
}
2 changes: 1 addition & 1 deletion api/canvas/canvasToBlob/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export function canvasToBlob (options, canvas) {

function toBlob (options, canvas, resolve) {
canvas.toBlob(resolve, options.mime, options.quality || 1)
}
}
2 changes: 1 addition & 1 deletion api/canvas/canvasToBuffer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { canvasToBlob } from '../canvasToBlob'

export function canvasToBuffer (options, canvas) {
return canvasToBlob(options, canvas).then(blobToBuffer)
}
}
2 changes: 1 addition & 1 deletion api/canvas/canvasToDataURL/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { canvasToBlob } from '../canvasToBlob'

export function canvasToDataURL (options, canvas) {
return canvasToBlob(options, canvas).then(blobToDataURL)
}
}
2 changes: 1 addition & 1 deletion api/canvas/canvasToImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { canvasToBlob } from '../canvasToBlob'

export function canvasToImage (options, canvas) {
return canvasToBlob(options, canvas).then(blobToImage)
}
}
2 changes: 1 addition & 1 deletion api/canvas/canvasToText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { canvasToBlob } from '../canvasToBlob'

export function canvasToText (options, canvas) {
return canvasToBlob(options, canvas).then(blobToText)
}
}
10 changes: 4 additions & 6 deletions api/dataURL/dataURLToImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import { onceLoad } from '../../../dom/emitter/once/onceLoad'
import { global } from '../../../global'
import { promise } from '../../../primitive/function/promise'

const
window = global(),
Image = window.Image
const window = global()
const Image = window.Image

export function dataURLToImage (url) {
return promise(read, url).then(getTarget)
}

function read (url, resolve, reject) {
const
img = new Image()
const img = new Image()

img.src = url
onceLoad(img, resolve)
onceError(img, reject)
}
}
2 changes: 1 addition & 1 deletion api/image/compressImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ function read (options, canvas, blob) {
options.quality = 1 - options.maxSize / blob.size

return compress(options, canvas)
}
}
4 changes: 2 additions & 2 deletions api/image/imageFromInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function imageFromInput (input, callback) {

function read (callback, event) {
const
file = ( event.dataTransfer || event.target ).files[0]
file = (event.dataTransfer || event.target).files[0]

callback(blobToImage(file))
}
}
2 changes: 1 addition & 1 deletion api/image/imageToBlob/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { imageToCanvas } from '../imageToCanvas'

export function imageToBlob (options, img) {
return imageToCanvas(img).then(curry(canvasToBlob, options))
}
}
2 changes: 1 addition & 1 deletion api/image/imageToBuffer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { imageToBlob } from '../imageToBlob'

export function imageToBuffer (options, img) {
return imageToBlob(options, img).then(blobToBuffer)
}
}
13 changes: 6 additions & 7 deletions api/image/imageToCanvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ export function imageToCanvas (img) {
}

function toCanvas (img, resolve) {
const
canvas = update(element('canvas'), {
width: img.naturalWidth,
height: img.naturalHeight,
}),
context = canvas.getContext('2d')
const canvas = update(element('canvas'), {
width: img.naturalWidth,
height: img.naturalHeight
})
const context = canvas.getContext('2d')

context.fillStyle = 'transparent'
context.fillRect(0, 0, img.naturalWidth, img.naturalHeight)
context.save()
context.drawImage(img, 0, 0)
resolve(canvas)
}
}
2 changes: 1 addition & 1 deletion api/image/imageToDataURL/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { imageToBlob } from '../imageToBlob'

export function imageToDataURL (options, img) {
return imageToBlob(options, img).then(blobToDataURL)
}
}
2 changes: 1 addition & 1 deletion api/image/imageToText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { imageToBlob } from '../imageToBlob'

export function imageToText (options, img) {
return imageToBlob(options, img).then(blobToText)
}
}
25 changes: 10 additions & 15 deletions api/image/resizeImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { promise } from '../../../primitive/function/promise'
import { create } from '../../../primitive/object/create'
import { canvasToImage } from '../../canvas/canvasToImage'

const
min = Math.min,
max = Math.max
const min = Math.min
const max = Math.max

export function resizeImage (options, img) {
options = parse(img.naturalWidth, img.naturalHeight, options)
Expand All @@ -15,8 +14,7 @@ export function resizeImage (options, img) {
}

function toCanvas (options, img, resolve) {
const
canvas = element('canvas')
const canvas = element('canvas')

canvas.width = options.width
canvas.height = options.height
Expand All @@ -26,8 +24,7 @@ function toCanvas (options, img, resolve) {
}

function draw (options, img, canvas) {
const
context = canvas.getContext('2d')
const context = canvas.getContext('2d')

context.fillStyle = 'transparent'
context.fillRect(0, 0, options.width, options.height)
Expand All @@ -37,9 +34,8 @@ function draw (options, img, canvas) {
}

function parse (width, height, options) {
const
result = create(),
ratio = width / height
const result = create()
const ratio = width / height

result.natural = normalize(width, height, ratio)
result.max = normalize(options.maxWidth, options.maxHeight, ratio, Infinity)
Expand All @@ -53,8 +49,7 @@ function parse (width, height, options) {
}

function normalize (width, height, ratio, defaultValue) {
const
config = create()
const config = create()

config.width = width || defaultValue
config.height = height || defaultValue
Expand All @@ -75,6 +70,6 @@ function normalize (width, height, ratio, defaultValue) {
}

function minMax (key, config) {
config[key] = ~~min(config.max[key], max(config.fixed[key], config.min[key]))
|| config.natural[key]
}
config[key] = ~~min(config.max[key], max(config.fixed[key], config.min[key])) ||
config.natural[key]
}
2 changes: 1 addition & 1 deletion dom/emitter/getTarget/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function getTarget (event) {
return event.target
}
}
4 changes: 2 additions & 2 deletions dom/emitter/off/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { global } from '../../../global'
import { callEach } from '../.callEach'

const
window = global();
window = global()

/**
* Forgets a listener of an event on an element (touch or not)
Expand All @@ -13,4 +13,4 @@ const
* @returns {Function} listener
*/
export const off = callEach.bind(null,
window.Element.prototype.removeEventListener)
window.Element.prototype.removeEventListener)
2 changes: 1 addition & 1 deletion dom/emitter/off/offBack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offBack (element, listener, useCapture) {
return off('keydown', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offBlur/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offBlur (element, listener, useCapture) {
return off('blur', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offChange/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offChange (element, listener, useCapture) {
return off('change', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offClick/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offClick (element, listener, useCapture) {
return off('click', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offDelete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offDelete (element, listener, useCapture) {
return off('keydown', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offDown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offDown (element, listener, useCapture) {
return off('keydown', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offDrag/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offDrag (element, listener, useCapture) {
return off('drag', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offDragEnter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offDragEnter (element, listener, useCapture) {
return off('dragenter', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offDrop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offDrop (element, listener, useCapture) {
return off('drop', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offEnter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offEnter (element, listener, useCapture) {
return off('keydown', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offError/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { off } from '..'

export function offError (element, listener, useCapture) {
return off('error', element, listener, useCapture)
}
}
2 changes: 1 addition & 1 deletion dom/emitter/off/offFileInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export function offFileInput (element, listener, useCapture) {

return listener
}
}
}
Loading

0 comments on commit 0780258

Please sign in to comment.