Revision 58170
Added by Konstantinos Triantafyllou about 4 years ago
string-utils.class.ts | ||
---|---|---|
86 | 86 |
export class DOI{ |
87 | 87 |
|
88 | 88 |
public static getDOIsFromString(str:string):string[]{ |
89 |
return Identifier.getDOIsFromString(str); |
|
90 |
} |
|
91 |
public static isValidDOI(str:string):boolean{ |
|
92 |
return Identifier.isValidDOI(str); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
export class Identifier{ |
|
97 |
class: "doi" | "pmc" | "pmid" | "handle"|"ORCID" =null; |
|
98 |
id:string; |
|
99 |
|
|
100 |
public static getDOIsFromString(str:string):string[]{ |
|
89 | 101 |
var DOIs:string[] = []; |
90 | 102 |
var words:string[] = str.split(" "); |
91 | 103 |
|
92 | 104 |
for(var i=0; i< words.length; i++){ |
93 |
if(DOI.isValidDOI(words[i]) && DOIs.indexOf(words[i]) == -1){
|
|
94 |
DOIs.push(words[i]);
|
|
95 |
}
|
|
105 |
if(DOI.isValidDOI(words[i]) && DOIs.indexOf(words[i]) == -1){ |
|
106 |
DOIs.push(words[i]); |
|
107 |
} |
|
96 | 108 |
} |
97 | 109 |
return DOIs; |
98 | 110 |
} |
99 |
public static isValidDOI(str:string):boolean{ |
|
111 |
public static getIdentifiersFromString(str:string):Identifier[]{ |
|
112 |
let identifiers:Identifier[] = []; |
|
113 |
let words:string[] = str.split(" "); |
|
100 | 114 |
|
101 |
var exp1 = /\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])\S)+)\b/g |
|
102 |
var exp2 = /\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])[[:graph:]])+)\b/g |
|
103 |
if(str.match(exp1)!=null || str.match(exp2)!=null){ |
|
104 |
// console.log("It's a DOI"); |
|
105 |
return true; |
|
115 |
for(let id of words){ |
|
116 |
if(id.length > 0 ) { |
|
117 |
if (Identifier.isValidDOI(id)) { |
|
118 |
identifiers.push({"class": "doi", "id": id}) |
|
119 |
} else if (Identifier.isValidORCID(id)) { |
|
120 |
identifiers.push({"class": "ORCID", "id": id}) |
|
121 |
} else if (Identifier.isValidPMCID(id)) { |
|
122 |
identifiers.push({"class": "pmc", "id": id}) |
|
123 |
} else if (Identifier.isValidPMID(id)) { |
|
124 |
identifiers.push({"class": "pmid", "id": id}) |
|
125 |
} else if (Identifier.isValidHANDLE(id)) { |
|
126 |
identifiers.push({"class": "handle", "id": id}) |
|
127 |
} |
|
106 | 128 |
} |
107 |
return false; |
|
129 |
} |
|
130 |
return identifiers; |
|
131 |
} |
|
132 |
public static isValidDOI(str:string):boolean{ |
|
133 |
var exp1 = /\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])\S)+)\b/g |
|
134 |
var exp2 = /\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?!["&\'<>])[[:graph:]])+)\b/g |
|
135 |
return (str.match(exp1)!=null || str.match(exp2)!=null); |
|
136 |
} |
|
137 |
public static isValidORCID(str:string):boolean{ |
|
138 |
let exp =/\b\d{4}-\d{4}-\d{4}-(\d{3}X|\d{4})\b/g; |
|
139 |
return str.match(exp)!=null; |
|
140 |
} |
|
141 |
public static isValidPMID(str:string):boolean{ |
|
142 |
let exp =/^\d*$/g; |
|
143 |
return str.match(exp)!=null; |
|
108 | 144 |
|
109 | 145 |
} |
146 |
public static isValidPMCID(str:string):boolean{ |
|
147 |
let exp =/^(PMC\d{7})$/g; |
|
148 |
return str.match(exp)!=null; |
|
149 |
} |
|
150 |
|
|
151 |
public static isValidHANDLE(str:string):boolean{ |
|
152 |
let exp =/^[0-9a-zA-Z-]*\/[0-9a-zA-Z-]*$/g; |
|
153 |
return str.match(exp)!=null; |
|
154 |
} |
|
110 | 155 |
} |
111 | 156 |
export class StringUtils{ |
112 | 157 |
public static quote(params: string):string { |
Also available in: Unified diff
[Library | Landing Redesign]: Merge from trunk