main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
754 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | function createMap(values, ignoreCase) {
|
---|
4 | var map = {};
|
---|
5 | values.forEach(function(value) {
|
---|
6 | map[value] = 1;
|
---|
7 | });
|
---|
8 | return ignoreCase ? function(value) {
|
---|
9 | return map[value.toLowerCase()] === 1;
|
---|
10 | } : function(value) {
|
---|
11 | return map[value] === 1;
|
---|
12 | };
|
---|
13 | }
|
---|
14 |
|
---|
15 | async function replaceAsync(str, regex, asyncFn) {
|
---|
16 | const promises = [];
|
---|
17 | str.replace(regex, (match, ...args) => {
|
---|
18 | const promise = asyncFn(match, ...args);
|
---|
19 | promises.push(promise);
|
---|
20 | });
|
---|
21 | const data = await Promise.all(promises);
|
---|
22 | return str.replace(regex, () => data.shift());
|
---|
23 | }
|
---|
24 |
|
---|
25 |
|
---|
26 | exports.createMap = createMap;
|
---|
27 | exports.createMapFromString = function(values, ignoreCase) {
|
---|
28 | return createMap(values.split(/,/), ignoreCase);
|
---|
29 | };
|
---|
30 |
|
---|
31 | exports.replaceAsync = replaceAsync;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.