@c-rex/utils 0.3.0-build.35 → 0.3.0-build.38
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/directoryNodes.js +2 -2
- package/dist/directoryNodes.js.map +1 -1
- package/dist/directoryNodes.mjs +2 -2
- package/dist/directoryNodes.mjs.map +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +66 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -113,8 +113,8 @@ type ParsedHtmlContent = {
|
|
|
113
113
|
metaTags: HtmlMetaTag[];
|
|
114
114
|
};
|
|
115
115
|
declare const parseHtmlContent: (html: string) => ParsedHtmlContent;
|
|
116
|
-
declare const getHtmlRenditionViewUrl: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => string | undefined;
|
|
117
116
|
declare const getHtmlRendition: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => RenditionModel | undefined;
|
|
117
|
+
declare const getHtmlRenditionViewUrl: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => string | undefined;
|
|
118
118
|
declare const metaTagsToMetadata: (metaTags: HtmlMetaTag[]) => Pick<Metadata, "description" | "keywords" | "other">;
|
|
119
119
|
|
|
120
120
|
type RelatedFragmentLike = ObjectRefModel & {
|
|
@@ -129,4 +129,8 @@ interface FindRelatedFragmentOptions {
|
|
|
129
129
|
declare const findRelatedFragment: ({ item, informationSubjectIds, }: FindRelatedFragmentOptions) => RelatedFragmentLike | undefined;
|
|
130
130
|
declare const findRelatedFragmentShortId: (options: FindRelatedFragmentOptions) => string | undefined;
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
declare const getLocalStorageJson: <T>(key: string) => T | null;
|
|
133
|
+
declare const setLocalStorageJson: (key: string, value: unknown) => void;
|
|
134
|
+
declare const removeLocalStorageItem: (key: string) => void;
|
|
135
|
+
|
|
136
|
+
export { type FileRenditionActionGroup, type FileRenditionActionItem, type HtmlMetaTag, type ParsedHtmlContent, call, cn, createAvailableVersionList, createParams, extractCountryCodeFromLanguage, filteredItems, findRelatedFragment, findRelatedFragmentShortId, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, getCountryCodeByLang, getFileRenditionGroups, getFileRenditions, getHtmlRendition, getHtmlRenditionViewUrl, getLabelByLang, getLanguage, getLocalStorageJson, getTitle, getType, getVersions, isDate, isLanguage, metaTagsToMetadata, normalizeLanguageCode, parseHtmlContent, processDataToLabelValuePairs, removeLocalStorageItem, replacePathParams, resolveLabelByLanguage, resolvePreferredLanguage, setLocalStorageJson, sortAndDeduplicateLanguages, transformLanguageData };
|
package/dist/index.d.ts
CHANGED
|
@@ -113,8 +113,8 @@ type ParsedHtmlContent = {
|
|
|
113
113
|
metaTags: HtmlMetaTag[];
|
|
114
114
|
};
|
|
115
115
|
declare const parseHtmlContent: (html: string) => ParsedHtmlContent;
|
|
116
|
-
declare const getHtmlRenditionViewUrl: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => string | undefined;
|
|
117
116
|
declare const getHtmlRendition: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => RenditionModel | undefined;
|
|
117
|
+
declare const getHtmlRenditionViewUrl: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => string | undefined;
|
|
118
118
|
declare const metaTagsToMetadata: (metaTags: HtmlMetaTag[]) => Pick<Metadata, "description" | "keywords" | "other">;
|
|
119
119
|
|
|
120
120
|
type RelatedFragmentLike = ObjectRefModel & {
|
|
@@ -129,4 +129,8 @@ interface FindRelatedFragmentOptions {
|
|
|
129
129
|
declare const findRelatedFragment: ({ item, informationSubjectIds, }: FindRelatedFragmentOptions) => RelatedFragmentLike | undefined;
|
|
130
130
|
declare const findRelatedFragmentShortId: (options: FindRelatedFragmentOptions) => string | undefined;
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
declare const getLocalStorageJson: <T>(key: string) => T | null;
|
|
133
|
+
declare const setLocalStorageJson: (key: string, value: unknown) => void;
|
|
134
|
+
declare const removeLocalStorageItem: (key: string) => void;
|
|
135
|
+
|
|
136
|
+
export { type FileRenditionActionGroup, type FileRenditionActionItem, type HtmlMetaTag, type ParsedHtmlContent, call, cn, createAvailableVersionList, createParams, extractCountryCodeFromLanguage, filteredItems, findRelatedFragment, findRelatedFragmentShortId, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, getCountryCodeByLang, getFileRenditionGroups, getFileRenditions, getHtmlRendition, getHtmlRenditionViewUrl, getLabelByLang, getLanguage, getLocalStorageJson, getTitle, getType, getVersions, isDate, isLanguage, metaTagsToMetadata, normalizeLanguageCode, parseHtmlContent, processDataToLabelValuePairs, removeLocalStorageItem, replacePathParams, resolveLabelByLanguage, resolvePreferredLanguage, setLocalStorageJson, sortAndDeduplicateLanguages, transformLanguageData };
|
package/dist/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __export(index_exports, {
|
|
|
48
48
|
getHtmlRenditionViewUrl: () => getHtmlRenditionViewUrl,
|
|
49
49
|
getLabelByLang: () => getLabelByLang,
|
|
50
50
|
getLanguage: () => getLanguage,
|
|
51
|
+
getLocalStorageJson: () => getLocalStorageJson,
|
|
51
52
|
getTitle: () => getTitle,
|
|
52
53
|
getType: () => getType,
|
|
53
54
|
getVersions: () => getVersions,
|
|
@@ -57,9 +58,11 @@ __export(index_exports, {
|
|
|
57
58
|
normalizeLanguageCode: () => normalizeLanguageCode,
|
|
58
59
|
parseHtmlContent: () => parseHtmlContent,
|
|
59
60
|
processDataToLabelValuePairs: () => processDataToLabelValuePairs,
|
|
61
|
+
removeLocalStorageItem: () => removeLocalStorageItem,
|
|
60
62
|
replacePathParams: () => replacePathParams,
|
|
61
63
|
resolveLabelByLanguage: () => resolveLabelByLanguage,
|
|
62
64
|
resolvePreferredLanguage: () => resolvePreferredLanguage,
|
|
65
|
+
setLocalStorageJson: () => setLocalStorageJson,
|
|
63
66
|
sortAndDeduplicateLanguages: () => sortAndDeduplicateLanguages,
|
|
64
67
|
transformLanguageData: () => transformLanguageData
|
|
65
68
|
});
|
|
@@ -1737,7 +1740,18 @@ var transformLanguageData = (data) => {
|
|
|
1737
1740
|
value: normalizedValue
|
|
1738
1741
|
};
|
|
1739
1742
|
});
|
|
1740
|
-
return countryCodeList.
|
|
1743
|
+
return countryCodeList.reduce((acc, item) => {
|
|
1744
|
+
const existingIndex = acc.findIndex((existing) => existing.lang === item.lang);
|
|
1745
|
+
if (existingIndex !== -1) {
|
|
1746
|
+
const existing = acc[existingIndex];
|
|
1747
|
+
if (item.value.includes("-") && !existing.value.includes("-")) {
|
|
1748
|
+
acc[existingIndex] = item;
|
|
1749
|
+
}
|
|
1750
|
+
} else {
|
|
1751
|
+
acc.push(item);
|
|
1752
|
+
}
|
|
1753
|
+
return acc;
|
|
1754
|
+
}, []).sort((a, b) => {
|
|
1741
1755
|
return a.value.localeCompare(b.value);
|
|
1742
1756
|
});
|
|
1743
1757
|
};
|
|
@@ -1782,10 +1796,10 @@ var getType = (classObj, lang = EN_LANG) => {
|
|
|
1782
1796
|
};
|
|
1783
1797
|
var getTitle = (titles, labels) => {
|
|
1784
1798
|
if (titles) {
|
|
1785
|
-
return titles[0]?.value;
|
|
1799
|
+
return titles[0]?.value || "NO TITLE";
|
|
1786
1800
|
}
|
|
1787
1801
|
if (labels) {
|
|
1788
|
-
return labels[0]?.value;
|
|
1802
|
+
return labels[0]?.value || "NO TITLE";
|
|
1789
1803
|
}
|
|
1790
1804
|
return "NO TITLE";
|
|
1791
1805
|
};
|
|
@@ -1812,21 +1826,24 @@ var parseHtmlContent = (html) => {
|
|
|
1812
1826
|
const content = $(el).attr("content");
|
|
1813
1827
|
return name && content ? { name, content } : null;
|
|
1814
1828
|
}).get().filter((tag) => tag !== null);
|
|
1815
|
-
const articleHtml = $("main").html() ||
|
|
1829
|
+
const articleHtml = $("main").html() || "";
|
|
1816
1830
|
return {
|
|
1817
1831
|
articleHtml,
|
|
1818
1832
|
metaTags
|
|
1819
1833
|
};
|
|
1820
1834
|
};
|
|
1821
|
-
var getHtmlRenditionViewUrl = (renditions, htmlFormats = ["application/xhtml+xml", "application/html", "text/html"]) => {
|
|
1822
|
-
const htmlRendition = getHtmlRendition(renditions, htmlFormats);
|
|
1823
|
-
const href = htmlRendition?.links?.find((link) => link.rel === "view")?.href;
|
|
1824
|
-
return href ?? void 0;
|
|
1825
|
-
};
|
|
1826
1835
|
var getHtmlRendition = (renditions, htmlFormats = ["application/xhtml+xml", "application/html", "text/html"]) => {
|
|
1827
1836
|
if (!renditions || renditions.length === 0) return void 0;
|
|
1828
1837
|
return renditions.find((rendition) => !!rendition.format && htmlFormats.includes(rendition.format));
|
|
1829
1838
|
};
|
|
1839
|
+
var getHtmlRenditionViewUrl = (renditions, htmlFormats = ["application/xhtml+xml", "application/html", "text/html"]) => {
|
|
1840
|
+
if (!renditions || renditions.length === 0) return void 0;
|
|
1841
|
+
const htmlRendition = renditions.find((rendition) => {
|
|
1842
|
+
return !!rendition.format && htmlFormats.includes(rendition.format);
|
|
1843
|
+
});
|
|
1844
|
+
const href = htmlRendition?.links?.find((link) => link.rel === "view")?.href;
|
|
1845
|
+
return href ?? void 0;
|
|
1846
|
+
};
|
|
1830
1847
|
var metaTagsToMetadata = (metaTags) => {
|
|
1831
1848
|
const description = metaTags.find((metaTag) => metaTag.name === "description")?.content;
|
|
1832
1849
|
const keywordsRaw = metaTags.find((metaTag) => metaTag.name === "keywords")?.content;
|
|
@@ -1865,6 +1882,43 @@ var findRelatedFragment = ({
|
|
|
1865
1882
|
var findRelatedFragmentShortId = (options) => {
|
|
1866
1883
|
return findRelatedFragment(options)?.shortId || void 0;
|
|
1867
1884
|
};
|
|
1885
|
+
|
|
1886
|
+
// src/local-storage.ts
|
|
1887
|
+
var getLocalStorage = () => {
|
|
1888
|
+
if (typeof window === "undefined") {
|
|
1889
|
+
return null;
|
|
1890
|
+
}
|
|
1891
|
+
return window.localStorage;
|
|
1892
|
+
};
|
|
1893
|
+
var getLocalStorageJson = (key) => {
|
|
1894
|
+
const storage = getLocalStorage();
|
|
1895
|
+
if (!storage) {
|
|
1896
|
+
return null;
|
|
1897
|
+
}
|
|
1898
|
+
const value = storage.getItem(key);
|
|
1899
|
+
if (!value) {
|
|
1900
|
+
return null;
|
|
1901
|
+
}
|
|
1902
|
+
try {
|
|
1903
|
+
return JSON.parse(value);
|
|
1904
|
+
} catch {
|
|
1905
|
+
return null;
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
var setLocalStorageJson = (key, value) => {
|
|
1909
|
+
const storage = getLocalStorage();
|
|
1910
|
+
if (!storage) {
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
storage.setItem(key, JSON.stringify(value));
|
|
1914
|
+
};
|
|
1915
|
+
var removeLocalStorageItem = (key) => {
|
|
1916
|
+
const storage = getLocalStorage();
|
|
1917
|
+
if (!storage) {
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
storage.removeItem(key);
|
|
1921
|
+
};
|
|
1868
1922
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1869
1923
|
0 && (module.exports = {
|
|
1870
1924
|
call,
|
|
@@ -1885,6 +1939,7 @@ var findRelatedFragmentShortId = (options) => {
|
|
|
1885
1939
|
getHtmlRenditionViewUrl,
|
|
1886
1940
|
getLabelByLang,
|
|
1887
1941
|
getLanguage,
|
|
1942
|
+
getLocalStorageJson,
|
|
1888
1943
|
getTitle,
|
|
1889
1944
|
getType,
|
|
1890
1945
|
getVersions,
|
|
@@ -1894,9 +1949,11 @@ var findRelatedFragmentShortId = (options) => {
|
|
|
1894
1949
|
normalizeLanguageCode,
|
|
1895
1950
|
parseHtmlContent,
|
|
1896
1951
|
processDataToLabelValuePairs,
|
|
1952
|
+
removeLocalStorageItem,
|
|
1897
1953
|
replacePathParams,
|
|
1898
1954
|
resolveLabelByLanguage,
|
|
1899
1955
|
resolvePreferredLanguage,
|
|
1956
|
+
setLocalStorageJson,
|
|
1900
1957
|
sortAndDeduplicateLanguages,
|
|
1901
1958
|
transformLanguageData
|
|
1902
1959
|
});
|