1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 01:57:19 +00:00

Added flag to $tw.utils.parseStringArray to allow non-unique entries (#2027)

* Added flag to $tw.utils.parseStringArray to allow non-unique entries

With this change if you use $tw.utils.parseStringArray(list) you get identical behavior to before and enforces uniqueness in lists, but if you use $tw.utils.parseStringArray(list,true) it allows duplicate values in the list.

Because of how JavaScript handles overloaded functions this shouldn't have any affect on existing code that just passes one argument to the function.

* Update to hopefully remove merge conflicts
This commit is contained in:
jed 2018-10-21 17:58:41 +02:00 committed by Jeremy Ruston
parent c0c1b557eb
commit baddd89abb

View File

@ -268,7 +268,7 @@ $tw.utils.stringifyList = function(value) {
};
// Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne"
$tw.utils.parseStringArray = function(value) {
$tw.utils.parseStringArray = function(value, allowDuplicate) {
if(typeof value === "string") {
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
results = [], names = {},
@ -277,7 +277,7 @@ $tw.utils.parseStringArray = function(value) {
match = memberRegExp.exec(value);
if(match) {
var item = match[1] || match[2];
if(item !== undefined && !$tw.utils.hop(names,item)) {
if(item !== undefined && (!$tw.utils.hop(names,item) || allowDuplicate)) {
results.push(item);
names[item] = true;
}