mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 01:27:41 +00:00
Fix: Parser improvements and lint fixes
This commit is contained in:
@@ -1,26 +1,14 @@
|
|||||||
/** Extracts the key and value from a passed in env string based on the provided delimiters. */
|
/** Extracts the key and value from a passed in env string based on the provided delimiters. */
|
||||||
export const getKeyValue = (pastedContent: string, delimiters: string[]) => {
|
export const getKeyValue = (pastedContent: string, delimiters: string[]) => {
|
||||||
let splitIndex = -1
|
const foundDelimiter = delimiters.find((delimiter) => pastedContent.includes(delimiter));
|
||||||
let key = ""
|
|
||||||
let value = ""
|
|
||||||
|
|
||||||
for (const delimiter of delimiters) {
|
if (!foundDelimiter) {
|
||||||
const idx = pastedContent.indexOf(delimiter)
|
return { key: pastedContent.trim(), value: "" };
|
||||||
|
|
||||||
if (idx !== -1) {
|
|
||||||
splitIndex = idx
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if only key is pasted
|
const [key, value] = pastedContent.split(foundDelimiter);
|
||||||
if (splitIndex === -1) {
|
return {
|
||||||
key = pastedContent.trim()
|
key: key.trim(),
|
||||||
return { key, value: "" }
|
value: (value ?? "").trim()
|
||||||
}
|
};
|
||||||
|
|
||||||
key = pastedContent.slice(0, splitIndex).trim()
|
|
||||||
value = pastedContent.slice(splitIndex + 1).trim()
|
|
||||||
|
|
||||||
return { key, value }
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user