@sparted/shared-library 1.0.4 → 1.0.6

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.
@@ -6,7 +6,7 @@ export declare type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue
6
6
  /**
7
7
  * Transform the initial data into another value
8
8
  */
9
- dataModifier?: (value: InitialValue) => ModifiedValue;
9
+ dataModifier?: (value: InitialValue, map: Readonly<Record<string, ModifiedValue>>) => ModifiedValue;
10
10
  };
11
11
  /**
12
12
  * Transform an array to a map.
@@ -10,7 +10,7 @@ const arrayToMap = (array, options) => {
10
10
  return array.reduce((acc, current) => {
11
11
  const key = selectKey(current);
12
12
  const value = options.dataModifier
13
- ? options.dataModifier(current)
13
+ ? options.dataModifier(current, acc)
14
14
  : current;
15
15
  return Object.assign(Object.assign({}, acc), { [key]: value });
16
16
  }, {});
@@ -1 +1 @@
1
- {"version":3,"file":"array-to-map.js","sources":["../../src/array/array-to-map.ts"],"sourcesContent":["export type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue> = {\n /**\n * Function to return the key used in the map.\n */\n selectKey: (value: InitialValue) => string,\n /**\n * Transform the initial data into another value\n */\n dataModifier?: (value: InitialValue) => ModifiedValue;\n};\n\n/**\n * Transform an array to a map.\n */\nexport const arrayToMap = <InitialValue, ModifiedValue = InitialValue>(\n array: ReadonlyArray<InitialValue>,\n options: ArrayToMapOptions<InitialValue, ModifiedValue>,\n) => {\n const { selectKey } = options;\n\n return array.reduce<Record<string, ModifiedValue>>((acc, current) => {\n const key = selectKey(current);\n const value = options.dataModifier\n ? options.dataModifier(current)\n : current;\n\n return {\n ...acc,\n [key]: value as ModifiedValue,\n };\n }, {});\n};\n"],"names":[],"mappings":";;;;AAWA;;AAEG;MACU,UAAU,GAAG,CACxB,KAAkC,EAClC,OAAuD,KACrD;AACF,IAAA,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO,KAAK,CAAC,MAAM,CAAgC,CAAC,GAAG,EAAE,OAAO,KAAI;AAClE,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY;AAChC,cAAE,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;cAC7B,OAAO,CAAC;AAEZ,QAAA,OAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACK,GAAG,CACN,EAAA,EAAA,CAAC,GAAG,GAAG,KAAsB,EAC7B,CAAA,CAAA;KACH,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
1
+ {"version":3,"file":"array-to-map.js","sources":["../../src/array/array-to-map.ts"],"sourcesContent":["export type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue> = {\n /**\n * Function to return the key used in the map.\n */\n selectKey: (value: InitialValue) => string,\n /**\n * Transform the initial data into another value\n */\n dataModifier?: (value: InitialValue, map: Readonly<Record<string, ModifiedValue>>) => ModifiedValue;\n};\n\n/**\n * Transform an array to a map.\n */\nexport const arrayToMap = <InitialValue, ModifiedValue = InitialValue>(\n array: ReadonlyArray<InitialValue>,\n options: ArrayToMapOptions<InitialValue, ModifiedValue>,\n) => {\n const { selectKey } = options;\n\n return array.reduce<Record<string, ModifiedValue>>((acc, current) => {\n const key = selectKey(current);\n const value = options.dataModifier\n ? options.dataModifier(current, acc)\n : current;\n\n return {\n ...acc,\n [key]: value as ModifiedValue,\n };\n }, {});\n};\n"],"names":[],"mappings":";;;;AAWA;;AAEG;MACU,UAAU,GAAG,CACxB,KAAkC,EAClC,OAAuD,KACrD;AACF,IAAA,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO,KAAK,CAAC,MAAM,CAAgC,CAAC,GAAG,EAAE,OAAO,KAAI;AAClE,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY;cAC9B,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC;cAClC,OAAO,CAAC;AAEZ,QAAA,OAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACK,GAAG,CACN,EAAA,EAAA,CAAC,GAAG,GAAG,KAAsB,EAC7B,CAAA,CAAA;KACH,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
@@ -2,17 +2,19 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _tslib = require('../_virtual/_tslib.js');
6
5
  var getCdnFromS3Url_util = require('./utils/get-cdn-from-s3-url.util.js');
7
6
  var getCdnUrl_util = require('./utils/get-cdn-url.util.js');
8
7
 
9
- const imgixTransformationQueries = (_a) => {
10
- var { fit } = _a, rest = _tslib.__rest(_a, ["fit"]);
11
- return [
12
- '?auto=compress,format',
13
- ...Object.entries(Object.assign(Object.assign({}, (fit !== undefined && fit === 'crop' ? { fit } : {})), rest)).map(([k, v]) => `&${k}=${v}`),
14
- ].join('');
15
- };
8
+ const imgixTransformationQueries = ({ fit, devicePixelRatio, height, width, quality, }) => [
9
+ '?auto=compress,format',
10
+ fit === 'crop' ? '&fit=crop' : '',
11
+ Number.isFinite(devicePixelRatio) ? `&dpr=${devicePixelRatio}` : '',
12
+ Number.isFinite(height) ? `&h=${height}` : '',
13
+ Number.isFinite(width) ? `&w=${width}` : '',
14
+ quality !== undefined && quality >= 0 && quality <= 100
15
+ ? `&q=${quality}`
16
+ : '',
17
+ ].join('');
16
18
  const twicpicsTransformationQueries = (params) => {
17
19
  if (params.fit !== undefined) {
18
20
  if (params.width === undefined || params.height === undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import 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 ...rest\n}) => [\n '?auto=compress,format',\n ...Object.entries({\n ...(fit !== undefined && fit === 'crop' ? { fit } : {}),\n ...rest,\n }).map(([k, v]) => `&${k}=${v}`),\n].join('');\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 return `?twic=v1/${params.fit}=${params.width}x${params.height}`;\n }\n if (params.width !== undefined) {\n const resizeHeight = params.height !== undefined ? `x${params.height}` : '';\n return `?twic=v1/resize=${params.width}${resizeHeight}`;\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":["__rest","getCdnUrlFactory","getCdnFromS3UrlFactory"],"mappings":";;;;;;;;AAIa,MAAA,0BAA0B,GAA0B,CAAC,EAGjE,KAAI;AAH6D,IAAA,IAAA,EAChE,GAAG,EAEJ,GAAA,EAAA,EADI,IAAI,GAAAA,aAAA,CAAA,EAAA,EAFyD,OAGjE,CADQ,CAAA;IACH,OAAA;QACJ,uBAAuB;AACvB,QAAA,GAAG,MAAM,CAAC,OAAO,kCACX,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAC,EACpD,IAAI,CACP,CAAA,CAAC,GAAG,CAA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S;SACV,CAAC;KACH,CAAC;AACJ;;;;;;"}
1
+ {"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import 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 devicePixelRatio,\n height,\n width,\n quality,\n}) => [\n '?auto=compress,format',\n fit === 'crop' ? '&fit=crop' : '',\n Number.isFinite(devicePixelRatio) ? `&dpr=${devicePixelRatio}` : '',\n Number.isFinite(height) ? `&h=${height}` : '',\n Number.isFinite(width) ? `&w=${width}` : '',\n quality !== undefined && quality >= 0 && quality <= 100\n ? `&q=${quality}`\n : '',\n].join('');\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 return `?twic=v1/${params.fit}=${params.width}x${params.height}`;\n }\n if (params.width !== undefined) {\n const resizeHeight = params.height !== undefined ? `x${params.height}` : '';\n return `?twic=v1/resize=${params.width}${resizeHeight}`;\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":["getCdnUrlFactory","getCdnFromS3UrlFactory"],"mappings":";;;;;;;AAIa,MAAA,0BAA0B,GAA0B,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GAAG,EAAE,CAAC;AAC5E,QAAA,OAAO,mBAAmB,MAAM,CAAC,KAAK,CAAG,EAAA,YAAY,EAAE,CAAC;AACzD,KAAA;AACD,IAAA,OAAO,EAAE,CAAC;AACZ,EAAE;AAEF;;;;;;AAMG;AACI,MAAM,SAAS,GAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,KAAI;IACvE,MAAM,SAAS,GAAGA,+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;;;;;;"}
@@ -3,6 +3,8 @@ export declare type Transformation = {
3
3
  fit?: 'crop' | 'contain';
4
4
  width?: number;
5
5
  height?: number;
6
+ devicePixelRatio?: number;
7
+ quality?: number;
6
8
  };
7
9
  export declare type CdnParams = {
8
10
  asThumbnail?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",