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
logging-improvements
jed 2018-10-21 17:58:41 +02:00 zatwierdzone przez Jeremy Ruston
rodzic c0c1b557eb
commit baddd89abb
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -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;
}