function parse(str) {
const result = [];
let openBrackets = 0;
let regExpString = "";
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (char === "{") {
openBrackets++;
if (openBrackets === 1) {
continue;
}
}
else if (char === "}") {
openBrackets--;
if (openBrackets === 0) {
regExpString = regExpString.replace(/(^\/)|(\/$)/g, "");
result.push(new RegExp(regExpString));
regExpString = "";
continue;
}
}
if (openBrackets === 0) {
switch (char) {
case "0": {
result.push(/\d/);
break;
}
default: {
result.push(char);
}
}
}
else {
regExpString += char;
}
}
return result;
}
const str = "+1({/[1-9]/}00) 000 000{/[1-9]/}";
const r = parse(str);
console.log(r); // -> ["+", "1", "(", /[1-9]/, /\d/, /\d/, ")", " ", /\d/, /\d/, /\d/, " ", /\d/, /\d/, /\d/, /[1-9]/]
function animateValues(elems) {
elems = Array.from(elems);
const endValues = elems.map(el => Number(el.dataset.value));
const currValues = new Array(elems.length).fill(0);
function loop() {
let doneCount = 0;
for (let i = 0; i < elems.length; i++) {
if (currValues[i] === endValues[i]) {
doneCount++;
}
else {
currValues[i]++;
elems[i].innerText = currValues[i];
}
}
if (doneCount !== elems.length) setTimeout(loop, 20);
}
setTimeout(loop, 0);
}
.text p {
display: inline-block;
position: relative;
}
.text p::before {
content: '';
position: absolute;
left: -30px;
right: -30px;
top: -10px;
height: 6px;
background: radial-gradient(circle, #000 2px, transparent 3px) space center / 10px 6px;
opacity: 0.3;
}
function zoom(e) {
const zoomer = e.currentTarget;
let offsetX, offsetY;
if (e.touches) {
offsetX = e.touches[0].pageX;
offsetY = e.touches[0].pageY;
} else {
offsetX = e.offsetX;
offsetY = e.offsetY;
}
const x = offsetX/zoomer.offsetWidth*100
const y = offsetY/zoomer.offsetHeight*100
zoomer.style.backgroundPosition = x + '% ' + y + '%';
}