Skip to content

Commit

Permalink
[image-url] Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Apr 9, 2018
1 parent fa63389 commit 13b75dd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/@sanity/image-url/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
1 change: 1 addition & 0 deletions packages/@sanity/image-url/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line import/no-commonjs
module.exports = require('./lib/builder').default
2 changes: 1 addition & 1 deletion packages/@sanity/image-url/src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ImageUrlBuilder {

export default function urlBuilder(options) {
// Did we get a SanityClient?
if (options && typeof options.clientConfig == 'object') {
if (options && typeof options.clientConfig === 'object') {
// Inherit config from client
return new ImageUrlBuilder(null, {
baseUrl: options.clientConfig.apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
Expand Down
10 changes: 5 additions & 5 deletions packages/@sanity/image-url/src/urlForImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function parseSource(source) {
function parseAssetId(ref) {
const [, id, dimensionString, format] = ref.split('-')

if (!(typeof dimensionString == 'string')) {
if (!(typeof dimensionString === 'string')) {
throw new Error(
`Malformed asset _ref '${ref}'. Expected an id on the form "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg.`
)
Expand All @@ -125,8 +125,8 @@ function parseAssetId(ref) {

if (
!(
typeof id == 'string' &&
typeof format == 'string' &&
typeof id === 'string' &&
typeof format === 'string' &&
Number.isFinite(width) &&
Number.isFinite(height)
)
Expand All @@ -139,7 +139,7 @@ function parseAssetId(ref) {
return {id, width, height, format}
}

/* eslint-disable complexity */
// eslint-disable-next-line complexity
function specToImageUrl(spec) {
const cdnUrl = spec.baseUrl || 'https://cdn.sanity.io'
const filename = `${spec.asset.id}-${spec.asset.width}x${spec.asset.height}.${spec.asset.format}`
Expand Down Expand Up @@ -176,7 +176,7 @@ function specToImageUrl(spec) {
}
})

if (params.length == 0) {
if (params.length === 0) {
return baseUrl
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/image-url/test/builder.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sanityImage from '../src/builder'
import should from 'should'
import sanityImage from '../src/builder'
import {imageWithNoCropSpecified, croppedImage} from './fixtures'

const urlFor = sanityImage()
Expand Down
5 changes: 4 additions & 1 deletion packages/@sanity/image-url/test/parseSource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ function compareParsedSource(outputSource, exptectedSource) {
should(outputSource).have.keys('crop', 'hotspot')
}

describe('[image-url] parseSource', () => {
describe('parseSource', () => {
it('does correctly parse full image object', () => {
const parsedSource = parseSource(imageWithNoCropSpecified())
compareParsedSource(parsedSource, imageWithNoCropSpecified())
})

it('does correctly parse asset object', () => {
const parsedSource = parseSource(imageWithNoCropSpecified().asset._ref)
compareParsedSource(parsedSource, imageWithNoCropSpecified())
})

it('does correctly parse image asset _ref', () => {
const parsedSource = parseSource(imageWithNoCropSpecified().asset)
compareParsedSource(parsedSource, imageWithNoCropSpecified())
})

it('does not overwrite cropp or hotspot settings', () => {
should(parseSource(croppedImage())).deepEqual(croppedImage())
})
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/image-url/urlForImage.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line import/no-commonjs
module.exports = require('./lib/urlForImage').default

0 comments on commit 13b75dd

Please sign in to comment.