Skip to content

Commit

Permalink
feat: implement basic VueImgixClient
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickfogerty committed Apr 17, 2020
1 parent 28d421e commit b1c3036
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/vue-imgix/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './vue-imgix';
16 changes: 16 additions & 0 deletions src/plugins/vue-imgix/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface IImgixClientOptions {
domain: string;
}

export interface IBuildUrlObjectResult {
src: string;
srcset: string;
}
export type IBuildUrlObject = (
url: string,
options: {},
) => IBuildUrlObjectResult;

export interface IVueImgixClient {
buildUrlObject: IBuildUrlObject;
}
27 changes: 27 additions & 0 deletions src/plugins/vue-imgix/vue-imgix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ImgixClient from 'imgix-core-js';
import { IBuildUrlObjectResult, IImgixClientOptions, IVueImgixClient } from './types';

class VueImgixClient implements IVueImgixClient {
#client: ImgixClient;
constructor(options: IImgixClientOptions) {
this.#client = new ImgixClient(options)
}

buildUrlObject(url: string, options: {}): IBuildUrlObjectResult {
const src = this.#client.buildURL(url, options)
const srcset = this.#client.buildSrcSet(url, options)

return {src, srcset}
}
}

export const buildImgixClient = (options: IImgixClientOptions) => {
const client = new VueImgixClient({
...options,
});

return client;
};

export type { IVueImgixClient };

0 comments on commit b1c3036

Please sign in to comment.