@sparted/shared-library 1.0.11 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { CreateCdn, TransformationQueries } from './types';
1
+ import type { CdnConfig, CdnType, TransformationQueries } from './types';
2
2
  export declare const imgixTransformationQueries: TransformationQueries;
3
3
  export declare const twicpicsTransformationQueries: TransformationQueries;
4
4
  /**
@@ -6,6 +6,10 @@ export declare const twicpicsTransformationQueries: TransformationQueries;
6
6
  * @param type cdn provider: 'twicpics' | 'imgix'
7
7
  * @param domain provider domain
8
8
  * @param instanceMapper domain + the result of the instanceMapper will form the base path
9
+ * @param cacheVersion
9
10
  * @returns \{ getCdnUrl, transformationQueries \}
10
11
  */
11
- export declare const createCdn: CreateCdn;
12
+ export declare const createCdn: <T extends CdnType>({ type, domain, instanceMapper, cacheVersion }: CdnConfig<T>) => {
13
+ getCdnUrl: import("./types").GetCdnUrl;
14
+ getCdnFromS3Url: import("./types").GetCdnFromS3Url;
15
+ };
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var buildSearchParams = require('../http/build-search-params.js');
6
6
  var getCdnFromS3Url_util = require('./utils/get-cdn-from-s3-url.util.js');
7
7
  var getCdnUrl_util = require('./utils/get-cdn-url.util.js');
8
+ var twicpicsTransformations_util = require('./utils/twicpics-transformations.util.js');
8
9
 
9
10
  const imgixTransformationQueries = ({ fit, width, height, quality, compress = true, devicePixelRatio, }) => {
10
11
  const params = {
@@ -16,39 +17,51 @@ const imgixTransformationQueries = ({ fit, width, height, quality, compress = tr
16
17
  q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,
17
18
  };
18
19
  const searchParams = buildSearchParams.buildSearchParams(params).toString();
19
- return searchParams ? `?${searchParams}` : '';
20
+ return searchParams ? `${searchParams}` : '';
20
21
  };
21
22
  const twicpicsTransformationQueries = (params) => {
23
+ const transformations = [];
22
24
  if (params.fit !== undefined) {
23
25
  if (params.width === undefined || params.height === undefined) {
24
26
  // eslint-disable-next-line no-console
25
27
  console.error('⚠️ The Twicpics api needs a width and a height.');
26
28
  return '';
27
29
  }
28
- return `?twic=v1/${params.fit}=${params.width}x${params.height}`;
30
+ transformations.push([params.fit, `${params.width}x${params.height}`]);
29
31
  }
30
- if (params.width !== undefined) {
32
+ else if (params.width !== undefined) {
31
33
  const resizeHeight = params.height !== undefined
32
34
  ? `x${params.height}`
33
35
  : '';
34
- return `?twic=v1/cover=${params.width}${resizeHeight}`;
36
+ transformations.push([
37
+ 'cover',
38
+ `${params.width}${resizeHeight}`
39
+ ]);
35
40
  }
36
- return '';
41
+ if (params.output !== undefined) {
42
+ transformations.push([
43
+ 'output',
44
+ params.output
45
+ ]);
46
+ }
47
+ return twicpicsTransformations_util.twicpicsTransformationChainToString(transformations);
37
48
  };
38
49
  /**
39
50
  *
40
51
  * @param type cdn provider: 'twicpics' | 'imgix'
41
52
  * @param domain provider domain
42
53
  * @param instanceMapper domain + the result of the instanceMapper will form the base path
54
+ * @param cacheVersion
43
55
  * @returns \{ getCdnUrl, transformationQueries \}
44
56
  */
45
- const createCdn = ({ type, domain, instanceMapper }) => {
57
+ const createCdn = ({ type, domain, instanceMapper, cacheVersion }) => {
46
58
  const getCdnUrl = getCdnUrl_util.getCdnUrlFactory({
47
59
  domain,
48
60
  instanceMapper,
49
61
  transformationQueries: type === 'imgix'
50
62
  ? imgixTransformationQueries
51
63
  : twicpicsTransformationQueries,
64
+ cacheVersion,
52
65
  });
53
66
  return {
54
67
  getCdnUrl,
@@ -1 +1 @@
1
- {"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import { buildSearchParams } from '../http/build-search-params';\nimport type { CreateCdn, TransformationQueries } from './types';\nimport { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';\nimport { getCdnUrlFactory } from './utils/get-cdn-url.util';\n\nexport const imgixTransformationQueries: TransformationQueries = ({\n fit,\n width,\n height,\n quality,\n compress = true,\n devicePixelRatio,\n}) => {\n const params = {\n auto: compress ? 'compress,format' : undefined,\n fit: fit === 'crop' ? 'crop' : undefined,\n dpr: Number.isFinite(devicePixelRatio) ? devicePixelRatio : undefined,\n h: Number.isFinite(height) ? height : undefined,\n w: Number.isFinite(width) ? width : undefined,\n q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,\n };\n const searchParams = buildSearchParams(params).toString();\n\n return searchParams ? `?${searchParams}` : '';\n};\n\nexport const twicpicsTransformationQueries: TransformationQueries = (\n params,\n) => {\n if (params.fit !== undefined) {\n if (params.width === undefined || params.height === undefined) {\n // eslint-disable-next-line no-console\n console.error('⚠️ The Twicpics api needs a width and a height.');\n return '';\n }\n\n return `?twic=v1/${params.fit}=${params.width}x${params.height}`;\n }\n if (params.width !== undefined) {\n const resizeHeight = params.height !== undefined\n ? `x${params.height}`\n : '';\n\n return `?twic=v1/cover=${params.width}${resizeHeight}`;\n }\n\n return '';\n};\n\n/**\n *\n * @param type cdn provider: 'twicpics' | 'imgix'\n * @param domain provider domain\n * @param instanceMapper domain + the result of the instanceMapper will form the base path\n * @returns \\{ getCdnUrl, transformationQueries \\}\n */\nexport const createCdn: CreateCdn = ({ type, domain, instanceMapper }) => {\n const getCdnUrl = getCdnUrlFactory({\n domain,\n instanceMapper,\n transformationQueries:\n type === 'imgix'\n ? imgixTransformationQueries\n : twicpicsTransformationQueries,\n });\n\n return {\n getCdnUrl,\n getCdnFromS3Url: getCdnFromS3UrlFactory({\n getCdnUrl,\n }),\n };\n};\n"],"names":["buildSearchParams","getCdnUrlFactory","getCdnFromS3UrlFactory"],"mappings":";;;;;;;;MAKa,0BAA0B,GAA0B,CAAC,EAChE,GAAG,EACH,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,GAAG,IAAI,EACf,gBAAgB,GACjB,KAAI;AACH,IAAA,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ,GAAG,iBAAiB,GAA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AA;cACnB,EAAE,CAAC;AAEP,QAAA,OAAO,kBAAkB,MAAM,CAAC,KAAK,CAAG,EAAA,YAAY,EAAE,CAAC;AACxD,KAAA;AAED,IAAA,OAAO,EAAE,CAAC;AACZ,EAAE;AAEF;;;;;;AAMG;AACI,MAAM,SAAS,GAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,KAAI;IACvE,MAAM,SAAS,GAAGC,+BAAgB,CAAC;QACjC,MAAM;QACN,cAAc;QACd,qBAAqB,EACnB,IAAI,KAAK,OAAO;AACd,cAAE,0BAA0B;AAC5B,cAAE,6BAA6B;AACpC,KAAA,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,eAAe,EAAEC,2CAAsB,CAAC;YACtC,SAAS;SACV,CAAC;KACH,CAAC;AACJ;;;;;;"}
1
+ {"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import { buildSearchParams } from '../http/build-search-params';\nimport type { CdnConfig, CdnType, TransformationQueries, TwicpicsTransformationChain } from './types';\nimport { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';\nimport { getCdnUrlFactory } from './utils/get-cdn-url.util';\nimport { twicpicsTransformationChainToString } from './utils/twicpics-transformations.util';\n\nexport const imgixTransformationQueries: TransformationQueries = ({\n fit,\n width,\n height,\n quality,\n compress = true,\n devicePixelRatio,\n}) => {\n const params = {\n auto: compress ? 'compress,format' : undefined,\n fit: fit === 'crop' ? 'crop' : undefined,\n dpr: Number.isFinite(devicePixelRatio) ? devicePixelRatio : undefined,\n h: Number.isFinite(height) ? height : undefined,\n w: Number.isFinite(width) ? width : undefined,\n q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,\n };\n const searchParams = buildSearchParams(params).toString();\n\n return searchParams ? `${searchParams}` : '';\n};\n\nexport const twicpicsTransformationQueries: TransformationQueries = (\n params,\n) => {\n const transformations: TwicpicsTransformationChain = [];\n if (params.fit !== undefined) {\n if (params.width === undefined || params.height === undefined) {\n // eslint-disable-next-line no-console\n console.error('⚠️ The Twicpics api needs a width and a height.');\n return '';\n }\n\n transformations.push([params.fit, `${params.width}x${params.height}`]);\n } else if (params.width !== undefined) {\n const resizeHeight = params.height !== undefined\n ? `x${params.height}`\n : '';\n\n transformations.push([\n 'cover',\n `${params.width}${resizeHeight}`]);\n }\n\n if (params.output !== undefined) {\n transformations.push([\n 'output',\n params.output]);\n }\n\n return twicpicsTransformationChainToString(transformations);\n};\n\n/**\n *\n * @param type cdn provider: 'twicpics' | 'imgix'\n * @param domain provider domain\n * @param instanceMapper domain + the result of the instanceMapper will form the base path\n * @param cacheVersion\n * @returns \\{ getCdnUrl, transformationQueries \\}\n */\nexport const createCdn = <T extends CdnType>({ type, domain, instanceMapper, cacheVersion }: CdnConfig<T>) => {\n const getCdnUrl = getCdnUrlFactory({\n domain,\n instanceMapper,\n transformationQueries:\n type === 'imgix'\n ? imgixTransformationQueries\n : twicpicsTransformationQueries,\n cacheVersion,\n });\n\n return {\n getCdnUrl,\n getCdnFromS3Url: getCdnFromS3UrlFactory({\n getCdnUrl,\n }),\n };\n};\n"],"names":["buildSearchParams","twicpicsTransformationChainToString","getCdnUrlFactory","getCdnFromS3UrlFactory"],"mappings":";;;;;;;;;MAMa,0BAA0B,GAA0B,CAAC,EAChE,GAAG,EACH,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,GAAG,IAAI,EACf,gBAAgB,GACjB,KAAI;AACH,IAAA,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ,GAAG,iBAAiB,GAAG,SAAS;QAC9C,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS;AACxC,QAAA,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,GAAG,SAAS;AACrE,QAAA,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS;AAC/C,QAA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SAAS,EAAE;QAC/B,eAAe,CAAC,IAAI,CAAC;YACnB,QAAQ;AACR,YAAA,MAAM,CAAC,MAAM;AAAC,SAAA,CAAC,CAAC;AACnB,KAAA;AAED,IAAA,OAAOC,gEAAmC,CAAC,eAAe,CAAC,CAAC;AAC9D,EAAE;AAEF;;;;;;;AAOG;AACI,MAAM,SAAS,GAAG,CAAoB,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAgB,KAAI;IAC3G,MAAM,SAAS,GAAGC,+BAAgB,CAAC;QACjC,MAAM;QACN,cAAc;QACd,qBAAqB,EACnB,IAAI,KAAK,OAAO;AACd,cAAE,0BAA0B;AAC5B,cAAE,6BAA6B;QACnC,YAAY;AACb,KAAA,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,eAAe,EAAEC,2CAAsB,CAAC;YACtC,SAAS;SACV,CAAC;KACH,CAAC;AACJ;;;;;;"}
@@ -9,22 +9,29 @@ export declare type Transformation = {
9
9
  * Only for imgix transformations. Default is true.
10
10
  */
11
11
  compress?: boolean;
12
+ output?: 'jpeg' | 'png' | 'webp' | 'image';
12
13
  };
13
14
  export declare type CdnParams = {
14
15
  asThumbnail?: boolean;
15
16
  transformation?: Transformation;
16
17
  };
17
18
  export declare type TransformationQueries = (params: Transformation) => string;
19
+ declare type TwicpicsOutputTransformation = ['output', Transformation['output']];
20
+ declare type TwicpicsFitTransformation = ['cover' | 'crop' | 'contain', string];
21
+ export declare type TwicpicsTransformation = TwicpicsOutputTransformation | TwicpicsFitTransformation;
22
+ export declare type TwicpicsTransformationChain = TwicpicsTransformation[];
18
23
  export declare type GetCdnUrl = (instanceId: string, path: `/${string}`, params?: CdnParams) => string;
19
24
  export declare type GetCdnFromS3Url = (url: string, params?: CdnParams) => string;
20
25
  export declare type InstanceMapper = (instanceId: string) => string;
21
- export declare type CdnConfig = {
22
- type: 'twicpics' | 'imgix';
26
+ export declare type CdnType = 'twicpics' | 'imgix';
27
+ export declare type CdnConfig<T extends CdnType> = {
28
+ type: T;
23
29
  domain: `https://${string}`;
24
30
  instanceMapper: InstanceMapper;
31
+ cacheVersion?: T extends 'twicpics' ? number : undefined;
25
32
  };
26
33
  export declare type Cdn = {
27
34
  getCdnUrl: GetCdnUrl;
28
35
  getCdnFromS3Url: GetCdnFromS3Url;
29
36
  };
30
- export declare type CreateCdn = (config: CdnConfig) => Cdn;
37
+ export {};
@@ -3,6 +3,8 @@ declare type FactoryConfig = {
3
3
  domain: `https://${string}`;
4
4
  instanceMapper: InstanceMapper;
5
5
  transformationQueries: TransformationQueries;
6
+ cacheVersion?: number;
6
7
  };
8
+ export declare const genCacheVersionQuery: (cacheVersion?: number) => string;
7
9
  export declare const getCdnUrlFactory: (config: FactoryConfig) => GetCdnUrl;
8
10
  export {};
@@ -2,12 +2,20 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const DEFAULT_THUMBNAIL_CONFIG = { width: 300, height: 300 };
5
+ const DEFAULT_THUMBNAIL_CONFIG = {
6
+ width: 300,
7
+ height: 300,
8
+ };
9
+ const genCacheVersionQuery = (cacheVersion) => (cacheVersion ? `v=${cacheVersion}` : '');
6
10
  const getCdnUrlFactory = (config) => (instanceId, path, params = {}) => {
7
- const { domain, instanceMapper, transformationQueries } = config;
11
+ const { domain, instanceMapper, transformationQueries, cacheVersion, } = config;
8
12
  const { transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {}, } = params;
9
- return `${domain}${instanceMapper(instanceId)}${path}${transformationQueries(transformation)}`;
13
+ const transformationQuery = transformationQueries(transformation);
14
+ const cacheVersionQuery = genCacheVersionQuery(cacheVersion);
15
+ const hasQueryParams = [transformationQuery, cacheVersionQuery].some((query) => query !== '');
16
+ return `${domain}${instanceMapper(instanceId)}${path}${hasQueryParams ? '?' : ''}${transformationQuery}${cacheVersionQuery ? `&${cacheVersionQuery}` : ''}`;
10
17
  };
11
18
 
19
+ exports.genCacheVersionQuery = genCacheVersionQuery;
12
20
  exports.getCdnUrlFactory = getCdnUrlFactory;
13
21
  //# sourceMappingURL=get-cdn-url.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-cdn-url.util.js","sources":["../../../src/cdn/utils/get-cdn-url.util.ts"],"sourcesContent":["import type {\n GetCdnUrl,\n InstanceMapper,\n Transformation,\n TransformationQueries,\n} from '../types';\n\nconst DEFAULT_THUMBNAIL_CONFIG: Transformation = { width: 300, height: 300 };\n\ntype FactoryConfig = {\n domain: `https://${string}`;\n instanceMapper: InstanceMapper;\n transformationQueries: TransformationQueries;\n};\n\nexport const getCdnUrlFactory = (config: FactoryConfig): GetCdnUrl => (instanceId, path, params = {}) => {\n const { domain, instanceMapper, transformationQueries } = config;\n\n const {\n transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {},\n } = params;\n\n return `${domain}${instanceMapper(\n instanceId,\n )}${path}${transformationQueries(transformation)}`;\n};\n"],"names":[],"mappings":";;;;AAOA,MAAM,wBAAwB,GAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAQhE,MAAA,gBAAgB,GAAG,CAAC,MAAqB,KAAgB,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,KAAI;IACtG,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;AAEjE,IAAA,MAAM,EACJ,cAAc,GAAG,MAAM,CAAC,WAAW,GAAG,wBAAwB,GAAG,EAAE,GACpE,GAAG,MAAM,CAAC;AAEX,IAAA,OAAO,CAAG,EAAA,MAAM,CAAG,EAAA,cAAc,CAC/B,UAAU,CACX,CAAG,EAAA,IAAI,GAAG,qBAAqB,CAAC,cAAc,CAAC,EAAE,CAAC;AACrD;;;;"}
1
+ {"version":3,"file":"get-cdn-url.util.js","sources":["../../../src/cdn/utils/get-cdn-url.util.ts"],"sourcesContent":["import type {\n GetCdnUrl,\n InstanceMapper,\n Transformation,\n TransformationQueries,\n} from '../types';\n\nconst DEFAULT_THUMBNAIL_CONFIG: Transformation = {\n width: 300,\n height: 300,\n};\n\ntype FactoryConfig = {\n domain: `https://${string}`;\n instanceMapper: InstanceMapper;\n transformationQueries: TransformationQueries;\n cacheVersion?: number;\n};\n\nexport const genCacheVersionQuery = (cacheVersion?: number) => (cacheVersion ? `v=${cacheVersion}` : '');\n\nexport const getCdnUrlFactory = (config: FactoryConfig): GetCdnUrl => (instanceId, path, params = {}) => {\n const {\n domain,\n instanceMapper,\n transformationQueries,\n cacheVersion,\n } = config;\n\n const {\n transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {},\n } = params;\n\n const transformationQuery: string = transformationQueries(transformation);\n const cacheVersionQuery = genCacheVersionQuery(cacheVersion);\n const hasQueryParams = [transformationQuery, cacheVersionQuery].some((query) => query !== '');\n\n return `${domain}${instanceMapper(\n instanceId,\n )}${path}${hasQueryParams ? '?' : ''}${transformationQuery}${cacheVersionQuery ? `&${cacheVersionQuery}` : ''}`;\n};\n"],"names":[],"mappings":";;;;AAOA,MAAM,wBAAwB,GAAmB;AAC/C,IAAA,KAAK,EAAE,GAAG;AACV,IAAA,MAAM,EAAE,GAAG;CACZ,CAAC;MASW,oBAAoB,GAAG,CAAC,YAAqB,MAAM,YAAY,GAAG,KAAK,YAAY,CAAA,CAAE,GAAG,EAAE,EAAE;AAE5F,MAAA,gBAAgB,GAAG,CAAC,MAAqB,KAAgB,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,KAAI;IACtG,MAAM,EACJ,MAAM,EACN,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,GAAG,MAAM,CAAC;AAEX,IAAA,MAAM,EACJ,cAAc,GAAG,MAAM,CAAC,WAAW,GAAG,wBAAwB,GAAG,EAAE,GACpE,GAAG,MAAM,CAAC;AAEX,IAAA,MAAM,mBAAmB,GAAW,qBAAqB,CAAC,cAAc,CAAC,CAAC;AAC1E,IAAA,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;AAC7D,IAAA,MAAM,cAAc,GAAG,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,KAAK,EAAE,CAAC,CAAC;AAE9F,IAAA,OAAO,CAAG,EAAA,MAAM,CAAG,EAAA,cAAc,CAC/B,UAAU,CACX,CAAG,EAAA,IAAI,GAAG,cAAc,GAAG,GAAG,GAAG,EAAE,CAAG,EAAA,mBAAmB,CAAG,EAAA,iBAAiB,GAAG,CAAI,CAAA,EAAA,iBAAiB,EAAE,GAAG,EAAE,EAAE,CAAC;AAClH;;;;;"}
@@ -0,0 +1,2 @@
1
+ import { TwicpicsTransformationChain } from '../types';
2
+ export declare const twicpicsTransformationChainToString: (transformationChain: TwicpicsTransformationChain) => string;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const twicpicsTransformationChainToString = (transformationChain) => {
6
+ if (transformationChain.length === 0)
7
+ return '';
8
+ const transformations = transformationChain
9
+ .map(([key, value]) => `${key}=${value}`)
10
+ .join('/');
11
+ return `twic=v1/${transformations}`;
12
+ };
13
+
14
+ exports.twicpicsTransformationChainToString = twicpicsTransformationChainToString;
15
+ //# sourceMappingURL=twicpics-transformations.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twicpics-transformations.util.js","sources":["../../../src/cdn/utils/twicpics-transformations.util.ts"],"sourcesContent":["import { TwicpicsTransformationChain } from '../types';\n\nexport const twicpicsTransformationChainToString = (\n transformationChain: TwicpicsTransformationChain,\n): string => {\n if (transformationChain.length === 0) return '';\n\n const transformations = transformationChain\n .map(([key, value]) => `${key}=${value}`)\n .join('/');\n\n return `twic=v1/${transformations}`;\n};\n"],"names":[],"mappings":";;;;AAEa,MAAA,mCAAmC,GAAG,CACjD,mBAAgD,KACtC;AACV,IAAA,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,EAAE,CAAC;IAEhD,MAAM,eAAe,GAAG,mBAAmB;AACxC,SAAA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAG,EAAA,GAAG,CAAI,CAAA,EAAA,KAAK,EAAE,CAAC;SACxC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,OAAO,CAAA,QAAA,EAAW,eAAe,CAAA,CAAE,CAAC;AACtC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.11",
3
+ "version": "1.0.14",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
@@ -58,4 +58,4 @@
58
58
  "^.+\\.(t|j)s$": "ts-jest"
59
59
  }
60
60
  }
61
- }
61
+ }