-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from marmelab/fix/import-tag-duplicaion
Fix(import): tags and companies are no loger duplicated during imports
- Loading branch information
Showing
6 changed files
with
70 additions
and
26 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
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,48 @@ | ||
export const UNQUOTED_ALLOWED_CHARS = '[A-Za-zÀ-ÖØ-öø-ÿ0-9-]+'; | ||
export const QUOTED_ALLOWED_CHARS = '[A-Za-zÀ-ÖØ-öø-ÿ0-9, -]+'; | ||
export const LIST_REGEX_BASE = `(${UNQUOTED_ALLOWED_CHARS}|"${QUOTED_ALLOWED_CHARS}")(,(${UNQUOTED_ALLOWED_CHARS}|"${QUOTED_ALLOWED_CHARS}"))*`; | ||
|
||
/** | ||
* List represents a list of values, quoted or not. | ||
* | ||
* e.g. 1 | ||
* e.g 1,2 | ||
* e.g "a","b" | ||
* e.g "a",b | ||
*/ | ||
export function parseList(list: string) { | ||
const parsedItems = []; | ||
|
||
let currentItem = ''; | ||
let currentQuoted = false; | ||
for (const char of list) { | ||
if (char === ',') { | ||
if (currentQuoted) { | ||
currentItem += char; | ||
continue; | ||
} | ||
|
||
parsedItems.push(currentItem); | ||
currentItem = ''; | ||
continue; | ||
} | ||
|
||
if (char === '"') { | ||
currentQuoted = !currentQuoted; | ||
continue; | ||
} | ||
|
||
currentItem += char; | ||
} | ||
if (currentItem) { | ||
parsedItems.push(currentItem); | ||
} | ||
|
||
return parsedItems.map((v: string) => { | ||
const parsedFloat = Number.parseFloat(v); | ||
if (!Number.isNaN(parsedFloat)) { | ||
return parsedFloat; | ||
} | ||
return v; | ||
}); | ||
} |
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