-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "addict", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { VARIABLE_ID, VARIABLE_XML_PATH } from "@utils/contants"; | ||
|
||
import { DDIBaseObject, DDIDetailledObject } from "@model/ddi"; | ||
|
||
import { getCode, getElementURN, getLabelsByLang, getPreferedLabel } from "./common"; | ||
|
||
export const getVariables = (xmlDoc: Document | Element): DDIBaseObject[] => { | ||
const variables = xmlDoc.getElementsByTagName(VARIABLE_XML_PATH); | ||
return Array.from(variables).map(v => { | ||
const labels = v.getElementsByTagName("r:Content"); | ||
return { | ||
URN: getElementURN(v), | ||
label: getPreferedLabel(getLabelsByLang(labels)), | ||
type: VARIABLE_ID | ||
}; | ||
}); | ||
}; | ||
|
||
export const getVariable = (xmlDoc: Document, id: string): DDIDetailledObject => { | ||
const variables = xmlDoc.getElementsByTagName(VARIABLE_XML_PATH); | ||
const variable = Array.from(variables).find(v => { | ||
const foundId = v.querySelector("ID")?.textContent; | ||
return id === foundId; | ||
}); | ||
if (!variable) throw new Error(`Unknow Variable: ${id}`); | ||
const labels = variable.getElementsByTagName("r:Content"); | ||
|
||
return { | ||
URN: getElementURN(variable), | ||
labels: getLabelsByLang(labels), | ||
code: getCode(variable) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import { CATEGORY_SCHEME_ID, CATEGORY_ID, CATEGORY_SCHEME_LABEL, CATEGORY_LABEL } from "@utils/contants"; | ||
import { | ||
CATEGORY_SCHEME_ID, | ||
CATEGORY_ID, | ||
CATEGORY_SCHEME_LABEL, | ||
CATEGORY_LABEL, | ||
VARIABLE_ID, | ||
VARIABLE_LABEL | ||
} from "@utils/contants"; | ||
|
||
import { DDIBaseObject, DDIDetailledObject, DDIObjectIDs, DDIObjectLabels } from "@model/ddi"; | ||
|
||
import { getCategories, getCategory } from "./Category"; | ||
import { getCategoryScheme, getCategorySchemes } from "./CategoryScheme"; | ||
import { getVariable, getVariables } from "./Variable"; | ||
|
||
export const getDDIObjects = (xmlDoc: Document): DDIBaseObject[] => [ | ||
...getCategorySchemes(xmlDoc), | ||
...getCategories(xmlDoc) | ||
...getCategories(xmlDoc), | ||
...getVariables(xmlDoc) | ||
]; | ||
|
||
export const getDDIObject = (content: Document, type: DDIObjectIDs, id: string): DDIDetailledObject => { | ||
if (type === CATEGORY_SCHEME_ID) return getCategoryScheme(content, id); | ||
if (type === CATEGORY_ID) return getCategory(content, id); | ||
if (type === VARIABLE_ID) return getVariable(content, id); | ||
throw new Error(`Unknow DDI object type: ${type}`); | ||
}; | ||
|
||
export const getTitle = (type: DDIObjectIDs): DDIObjectLabels => { | ||
if (type === "category-scheme") return CATEGORY_SCHEME_LABEL; | ||
if (type === "category") return CATEGORY_LABEL; | ||
if (type === CATEGORY_SCHEME_ID) return CATEGORY_SCHEME_LABEL; | ||
if (type === CATEGORY_ID) return CATEGORY_LABEL; | ||
if (type === VARIABLE_ID) return VARIABLE_LABEL; | ||
throw new Error(`Unknow type: ${type}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1950,7 +1950,7 @@ [email protected]: | |
dependencies: | ||
"@remix-run/router" "1.21.0" | ||
|
||
react-syntax-highlighter@^15.5.13: | ||
react-syntax-highlighter@^15.6.1: | ||
version "15.6.1" | ||
resolved "https://registry.yarnpkg.com/react-syntax-highlighter/-/react-syntax-highlighter-15.6.1.tgz#fa567cb0a9f96be7bbccf2c13a3c4b5657d9543e" | ||
integrity sha512-OqJ2/vL7lEeV5zTJyG7kmARppUjiB9h9udl4qHQjjgEos66z00Ia0OckwYfRxCSFrW8RJIBnsBwQsHZbVPspqg== | ||
|