@sparted/shared-library 1.0.26 → 1.0.28-dev.0
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.
- package/cdn/cdn.factory.js +3 -5
- package/cdn/cdn.factory.js.map +1 -1
- package/cdn/utils/get-cdn-url.util.js +2 -2
- package/cdn/utils/get-cdn-url.util.js.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/string/index.d.ts +1 -0
- package/string/index.js +2 -0
- package/string/index.js.map +1 -1
- package/string/is-string-length-within-range.d.ts +2 -0
- package/string/is-string-length-within-range.js +14 -0
- package/string/is-string-length-within-range.js.map +1 -0
- package/types/general.d.ts +4 -0
package/cdn/cdn.factory.js
CHANGED
|
@@ -23,8 +23,8 @@ const twicpicsTransformationQueries = (params) => {
|
|
|
23
23
|
const quality = params.quality || 90;
|
|
24
24
|
const transformations = [['quality', quality]];
|
|
25
25
|
const dpr = params.devicePixelRatio || 1;
|
|
26
|
-
const width = params.width ? params.width * dpr : '-';
|
|
27
|
-
const height = params.height ? params.height * dpr : '-';
|
|
26
|
+
const width = params.width ? Math.round(params.width * dpr) : '-';
|
|
27
|
+
const height = params.height ? Math.round(params.height * dpr) : '-';
|
|
28
28
|
const fit = params.fit || 'cover';
|
|
29
29
|
if (params.width !== undefined || params.height !== undefined) {
|
|
30
30
|
transformations.push([fit, `${width}x${height}`]);
|
|
@@ -46,9 +46,7 @@ const createCdn = ({ type, domain, instanceMapper, cacheVersion }) => {
|
|
|
46
46
|
const getCdnUrl = getCdnUrl_util.getCdnUrlFactory({
|
|
47
47
|
domain,
|
|
48
48
|
instanceMapper,
|
|
49
|
-
transformationQueries: type === 'imgix'
|
|
50
|
-
? imgixTransformationQueries
|
|
51
|
-
: twicpicsTransformationQueries,
|
|
49
|
+
transformationQueries: type === 'imgix' ? imgixTransformationQueries : twicpicsTransformationQueries,
|
|
52
50
|
cacheVersion,
|
|
53
51
|
});
|
|
54
52
|
return {
|
package/cdn/cdn.factory.js.map
CHANGED
|
@@ -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 { 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 = (
|
|
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 = (params) => {\n const quality = params.quality || 90;\n const transformations: TwicpicsTransformationChain = [['quality', quality]];\n const dpr = params.devicePixelRatio || 1;\n\n const width = params.width ? Math.round(params.width * dpr) : '-';\n const height = params.height ? Math.round(params.height * dpr) : '-';\n const fit = params.fit || 'cover';\n\n if (params.width !== undefined || params.height !== undefined) {\n transformations.push([fit, `${width}x${height}`]);\n }\n\n if (params.output !== undefined) {\n transformations.push(['output', 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: type === 'imgix' ? imgixTransformationQueries : 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,gB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K,CAAI,CAAA,EAAA,MAAM,CAAE,CAAA,CAAC,CAAC,CAAC;AACnD,KAAA;AAED,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;QAC/B,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,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,EAAE,IAAI,KAAK,OAAO,GAAG,0BAA0B,GAAG,6BAA6B;QACpG,YAAY;AACb,KAAA,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,eAAe,EAAEC,2CAAsB,CAAC;YACtC,SAAS;SACV,CAAC;KACH,CAAC;AACJ;;;;;;"}
|
|
@@ -8,8 +8,8 @@ const DEFAULT_THUMBNAIL_CONFIG = {
|
|
|
8
8
|
};
|
|
9
9
|
const genCacheVersionQuery = (cacheVersion) => (cacheVersion ? `v=${cacheVersion}` : '');
|
|
10
10
|
const getCdnUrlFactory = (config) => (instanceId, path, params = {}) => {
|
|
11
|
-
const { domain, instanceMapper, transformationQueries, cacheVersion
|
|
12
|
-
const { transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {}
|
|
11
|
+
const { domain, instanceMapper, transformationQueries, cacheVersion } = config;
|
|
12
|
+
const { transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {} } = params;
|
|
13
13
|
const transformationQuery = transformationQueries(transformation);
|
|
14
14
|
const cacheVersionQuery = genCacheVersionQuery(cacheVersion);
|
|
15
15
|
const hasQueryParams = [transformationQuery, cacheVersionQuery].some((query) => query !== '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-cdn-url.util.js","sources":["../../../src/cdn/utils/get-cdn-url.util.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"get-cdn-url.util.js","sources":["../../../src/cdn/utils/get-cdn-url.util.ts"],"sourcesContent":["import type { GetCdnUrl, InstanceMapper, Transformation, TransformationQueries } 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 =\n (config: FactoryConfig): GetCdnUrl =>\n (instanceId, path, params = {}) => {\n const { domain, instanceMapper, transformationQueries, cacheVersion } = config;\n\n const { transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {} } = 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(instanceId)}${path}${hasQueryParams ? '?' : ''}${transformationQuery}${\n cacheVersionQuery ? `&${cacheVersionQuery}` : ''\n }`;\n };\n"],"names":[],"mappings":";;;;AAEA,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,GAC3B,CAAC,MAAqB,KACtB,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,KAAI;IAChC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;AAE/E,IAAA,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,WAAW,GAAG,wBAAwB,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;AAEvF,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,CAAC,UAAU,CAAC,CAAG,EAAA,IAAI,GAAG,cAAc,GAAG,GAAG,GAAG,EAAE,CAAG,EAAA,mBAAmB,CACpG,EAAA,iBAAiB,GAAG,CAAI,CAAA,EAAA,iBAAiB,EAAE,GAAG,EAChD,EAAE,CAAC;AACL;;;;;"}
|
package/index.js
CHANGED
|
@@ -36,6 +36,7 @@ var executeOrResolveDefault = require('./promise/execute-or-resolve-default.js')
|
|
|
36
36
|
var executeWithDelay = require('./promise/execute-with-delay.js');
|
|
37
37
|
var delay = require('./promise/delay.js');
|
|
38
38
|
var replaceInTemplate = require('./string/replace-in-template.js');
|
|
39
|
+
var isStringLengthWithinRange = require('./string/is-string-length-within-range.js');
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
|
|
@@ -80,4 +81,5 @@ exports.executeOrResolveDefault = executeOrResolveDefault.executeOrResolveDefaul
|
|
|
80
81
|
exports.executeWithDelay = executeWithDelay.executeWithDelay;
|
|
81
82
|
exports.delay = delay.delay;
|
|
82
83
|
exports.replaceInTemplate = replaceInTemplate.replaceInTemplate;
|
|
84
|
+
exports.isStringLengthWithinRange = isStringLengthWithinRange.isStringLengthWithinRange;
|
|
83
85
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
package/string/index.d.ts
CHANGED
package/string/index.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var replaceInTemplate = require('./replace-in-template.js');
|
|
6
|
+
var isStringLengthWithinRange = require('./is-string-length-within-range.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
exports.replaceInTemplate = replaceInTemplate.replaceInTemplate;
|
|
11
|
+
exports.isStringLengthWithinRange = isStringLengthWithinRange.isStringLengthWithinRange;
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
package/string/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const isStringLengthWithinRange = (range, str) => {
|
|
6
|
+
if (range.min > range.max) {
|
|
7
|
+
throw new Error('Invalid range');
|
|
8
|
+
}
|
|
9
|
+
const strLength = (str === null || str === void 0 ? void 0 : str.length) || 0;
|
|
10
|
+
return strLength >= (range.min || 0) && strLength <= range.max;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.isStringLengthWithinRange = isStringLengthWithinRange;
|
|
14
|
+
//# sourceMappingURL=is-string-length-within-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-string-length-within-range.js","sources":["../../src/string/is-string-length-within-range.ts"],"sourcesContent":["import { Range } from '../types/general';\n\nexport const isStringLengthWithinRange = (range: Range, str?: string) => {\n if (range.min > range.max) {\n throw new Error('Invalid range');\n }\n\n const strLength = str?.length || 0;\n return strLength >= (range.min || 0) && strLength <= range.max;\n}\n"],"names":[],"mappings":";;;;MAEa,yBAAyB,GAAG,CAAC,KAAY,EAAE,GAAY,KAAI;AACtE,IAAA,IAAI,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE;AACzB,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;AAClC,KAAA;AAED,IAAA,MAAM,SAAS,GAAG,CAAA,GAAG,KAAH,IAAA,IAAA,GAAG,KAAH,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,GAAG,CAAE,MAAM,KAAI,CAAC,CAAC;AACnC,IAAA,OAAO,SAAS,KAAK,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC;AACjE;;;;"}
|
package/types/general.d.ts
CHANGED
|
@@ -2,3 +2,7 @@ export type Primitive = string | number | boolean;
|
|
|
2
2
|
export type Nullable<T> = T | null;
|
|
3
3
|
export type ValueType = Primitive | null | void | Array<any> | ReadonlyArray<any>;
|
|
4
4
|
export type ValueOf<T> = T[keyof T];
|
|
5
|
+
export type Range = {
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
};
|