Skip to content

Commit 076c6f4

Browse files
committed
Update to use expect from ts-std
1 parent 9cd6545 commit 076c6f4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/lib/plugins/retina-images/walker.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { exists as _exists } from 'fs';
22
import _imageSize from 'image-size';
33
import { HTML, Image } from 'mdast';
44
import { basename, resolve } from 'path';
5+
import { expect } from 'ts-std';
56
import { promisify } from 'util';
67
import BaseWalker from '../../walker';
78
import Options from './options';
@@ -38,9 +39,14 @@ function attr(v: unknown): string {
3839

3940

4041
async function toImgTag(node: Image, options: Options): Promise<HTML> {
41-
let size = await imageSize(pathFor(node.url, options));
42-
let width = Math.floor(size!.width! / 2);
43-
let height = Math.floor(size!.height! / 2);
42+
let sizeOfImage = await imageSize(pathFor(node.url, options));
43+
44+
let size = expect(sizeOfImage, 'size should be present');
45+
let width = expect(size.width, 'width should be present');
46+
let height = expect(size.height, 'height should be present');
47+
48+
let widthAttr = Math.floor(width / 2);
49+
let heightAttr = Math.floor(height / 2);
4450

4551
let attrs = [];
4652

@@ -54,8 +60,8 @@ async function toImgTag(node: Image, options: Options): Promise<HTML> {
5460
attrs.push(`title=${attr(node.title)}`);
5561
}
5662

57-
attrs.push(`width=${attr(width)}`);
58-
attrs.push(`height=${attr(height)}`);
63+
attrs.push(`width=${attr(widthAttr)}`);
64+
attrs.push(`height=${attr(heightAttr)}`);
5965

6066
return {
6167
type: 'html',

0 commit comments

Comments
 (0)