@prezly/sdk 18.1.1 → 18.2.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/dist/api/constants.cjs +1 -1
- package/dist/api/constants.js +1 -1
- package/dist/types/Category.cjs +35 -1
- package/dist/types/Category.d.ts +24 -0
- package/dist/types/Category.js +35 -1
- package/package.json +1 -1
package/dist/api/constants.cjs
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.DEFAULT_USER_AGENT = void 0;
|
|
7
|
-
const VERSION = "18.1.
|
|
7
|
+
const VERSION = "18.1.1";
|
|
8
8
|
const URL = 'https://github.com/prezly/javascript-sdk';
|
|
9
9
|
const DEFAULT_USER_AGENT = `prezly-javascript-sdk/${VERSION} (+${URL})`;
|
|
10
10
|
exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
|
package/dist/api/constants.js
CHANGED
package/dist/types/Category.cjs
CHANGED
|
@@ -6,4 +6,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Category = void 0;
|
|
7
7
|
let Category;
|
|
8
8
|
exports.Category = Category;
|
|
9
|
-
(function (_Category) {
|
|
9
|
+
(function (_Category) {
|
|
10
|
+
function isTranslated(category, locale) {
|
|
11
|
+
const translation = category.i18n[localeCode(locale)];
|
|
12
|
+
return isNonEmpty(translation);
|
|
13
|
+
}
|
|
14
|
+
_Category.isTranslated = isTranslated;
|
|
15
|
+
function translation(category, locale) {
|
|
16
|
+
const [translation] = Category.translations(category, locale);
|
|
17
|
+
return translation;
|
|
18
|
+
}
|
|
19
|
+
_Category.translation = translation;
|
|
20
|
+
function translations(input, locale) {
|
|
21
|
+
const code = locale ? localeCode(locale) : undefined;
|
|
22
|
+
const categories = Array.isArray(input) ? input : [input];
|
|
23
|
+
return categories.reduce((result, category) => {
|
|
24
|
+
const translated = (code ? [category.i18n[code]] : Object.values(category.i18n)).filter(isNonEmpty).map(translation => {
|
|
25
|
+
return {
|
|
26
|
+
id: category.id,
|
|
27
|
+
locale: translation.locale.code,
|
|
28
|
+
slug: translation.slug,
|
|
29
|
+
name: translation.name,
|
|
30
|
+
description: translation.description
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return [...result, ...translated];
|
|
34
|
+
}, []);
|
|
35
|
+
}
|
|
36
|
+
_Category.translations = translations;
|
|
37
|
+
})(Category || (exports.Category = Category = {}));
|
|
38
|
+
function isNonEmpty(translation) {
|
|
39
|
+
return Boolean(translation && translation.name && translation.slug);
|
|
40
|
+
}
|
|
41
|
+
function localeCode(locale) {
|
|
42
|
+
return typeof locale === 'string' ? locale : locale.code;
|
|
43
|
+
}
|
package/dist/types/Category.d.ts
CHANGED
|
@@ -19,4 +19,28 @@ export declare namespace Category {
|
|
|
19
19
|
name: string;
|
|
20
20
|
description: string | null;
|
|
21
21
|
}
|
|
22
|
+
function isTranslated<T extends Category, LocaleCode extends Culture['code']>(category: T, locale: LocaleIdentifier<LocaleCode>): category is WithNonEmptyTranslation<T, LocaleCode>;
|
|
23
|
+
function translation<T extends Category, LocaleCode extends Culture['code']>(category: T, locale: LocaleIdentifier<LocaleCode>): T extends WithNonEmptyTranslation<Category, LocaleCode> ? TranslatedCategory : TranslatedCategory | undefined;
|
|
24
|
+
function translations(category: Category, locale?: LocaleIdentifier): TranslatedCategory[];
|
|
25
|
+
function translations(categories: Category[], locale?: LocaleIdentifier): TranslatedCategory[];
|
|
22
26
|
}
|
|
27
|
+
export interface TranslatedCategory {
|
|
28
|
+
id: Category['id'];
|
|
29
|
+
locale: Culture['code'];
|
|
30
|
+
slug: NonNullable<Category.Translation['slug']>;
|
|
31
|
+
name: Category.Translation['name'];
|
|
32
|
+
description: Category.Translation['description'];
|
|
33
|
+
}
|
|
34
|
+
declare type LocaleIdentifier<Locale extends Culture['code'] = Culture['code']> = Locale | {
|
|
35
|
+
code: Locale;
|
|
36
|
+
};
|
|
37
|
+
declare type NonEmptyTranslation = Category.Translation & {
|
|
38
|
+
slug: NonNullable<Category.Translation['slug']>;
|
|
39
|
+
name: Exclude<Category.Translation['name'], ''>;
|
|
40
|
+
};
|
|
41
|
+
declare type WithNonEmptyTranslation<T extends Category, LocaleCode extends Culture['code']> = T & {
|
|
42
|
+
i18n: {
|
|
43
|
+
[localeCode in LocaleCode]: NonEmptyTranslation;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {};
|
package/dist/types/Category.js
CHANGED
|
@@ -1,2 +1,36 @@
|
|
|
1
1
|
export let Category;
|
|
2
|
-
(function (_Category) {
|
|
2
|
+
(function (_Category) {
|
|
3
|
+
function isTranslated(category, locale) {
|
|
4
|
+
const translation = category.i18n[localeCode(locale)];
|
|
5
|
+
return isNonEmpty(translation);
|
|
6
|
+
}
|
|
7
|
+
_Category.isTranslated = isTranslated;
|
|
8
|
+
function translation(category, locale) {
|
|
9
|
+
const [translation] = Category.translations(category, locale);
|
|
10
|
+
return translation;
|
|
11
|
+
}
|
|
12
|
+
_Category.translation = translation;
|
|
13
|
+
function translations(input, locale) {
|
|
14
|
+
const code = locale ? localeCode(locale) : undefined;
|
|
15
|
+
const categories = Array.isArray(input) ? input : [input];
|
|
16
|
+
return categories.reduce((result, category) => {
|
|
17
|
+
const translated = (code ? [category.i18n[code]] : Object.values(category.i18n)).filter(isNonEmpty).map(translation => {
|
|
18
|
+
return {
|
|
19
|
+
id: category.id,
|
|
20
|
+
locale: translation.locale.code,
|
|
21
|
+
slug: translation.slug,
|
|
22
|
+
name: translation.name,
|
|
23
|
+
description: translation.description
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return [...result, ...translated];
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
29
|
+
_Category.translations = translations;
|
|
30
|
+
})(Category || (Category = {}));
|
|
31
|
+
function isNonEmpty(translation) {
|
|
32
|
+
return Boolean(translation && translation.name && translation.slug);
|
|
33
|
+
}
|
|
34
|
+
function localeCode(locale) {
|
|
35
|
+
return typeof locale === 'string' ? locale : locale.code;
|
|
36
|
+
}
|