Last active
May 16, 2019 01:53
-
-
Save dmtrmrv/835584b8481f7af212390329132e5c29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const artist = 'M1248 761h-48v72h-48v-72h-48v83h-48v113h-48V784h-48v82h-48v24h-48v-18h-48V767h-48v77h-48v-48h-48v85h-48v-65h-48v17h-48v-72h-48v83h-48v113h-48V784h-48v82h-48v24h-48v-18h-48v-56h-48v28H96v-48H48v85H0V85h48V0h48v48h48v84h48v-22h48V87h48V62h48v21h48v35h48V48h48v110h48v-32h48v20h48V85h48V0h48v48h48v84h48v-22h48V87h48V62h48v21h48v35h48V48h48v110h48v-32h48v32h48V87h48v71h48v603h-48v129h-48V761z'; | |
const product = 'M48 796V0h48v796H48zm96 20V132h48v684h-48zm96 74V87h48v803h-48zm96-106V83h48v701h-48zm96 60V48h48v796h-48zm96-11V126h48v707h-48zm96 48V85h48v796h-48zm96-37V48h48v796h-48zm96 28V110h48v762h-48zm96-6V62h48v804h-48zm96 91V118h48v839h-48zm96-196V158h48v603h-48zm96 23V83h48v701h-48zm96 60V48h48v796h-48z'; | |
const productMobile = 'M0 425V41.56h28.52V425H0zm57.04-50.61V39.64h28.52v334.75H57.04zm57.03 28.65V22.92h28.52v380.12h-28.52zm57.04-5.25V60.17h28.52v337.62h-28.52zm57.04 22.92V40.59h28.52v380.12h-28.52zm57.04-17.67V22.92h28.51v380.12H285.2zm57.03 13.37V52.53h28.52V416.4h-28.52zm57.04-2.87V29.61h28.52v383.93h-28.52z'; | |
const artistMobile = 'M428.44 39.64H457v334.75h-28.56v39.15h-28.56v11.47H371.3v-8.6h-28.56v-50.14h-28.56v36.77h-28.56v-22.92h-28.57v40.59H228.5v-31.04h-28.56v8.12h-28.56V363.4H142.8v39.64h-28.56V457H85.69v-82.61H57.13v39.15H28.55v11.47H0V41.55h28.56V29.6h28.57v10.03h28.56v16.7h28.56V22.93h28.56v52.53h28.56V60.17h28.57v9.55h28.56V40.59h28.56V0h28.56v22.92h28.57v40.11h28.56v-10.5h28.56V41.55h28.56V29.6h28.57v10.03z'; | |
function transformOne( data ) { | |
const regexNewLine = /[a-zA-Z]/g; | |
const regexSpace = /-/g; | |
const regexDoubleSpace = /\s{2}(?=(-|\d))/g; | |
const regexFix = /\d+/g; | |
const out = d | |
.replace(regexNewLine, `\n$& `) | |
.replace(regexSpace, ` $&`) | |
.replace(regexDoubleSpace, ` `) | |
.replace(regexFix, (match) => { | |
return match / 1344; | |
}); | |
return out | |
} | |
function transformTwo( data, width, height ) { | |
const regexNewLine = /[a-zA-Z]/g; | |
const regexSpace = /-/g; | |
const regexDoubleSpace = /\s{2}(?=(-|\d))/g; | |
const out = data | |
.replace(regexNewLine, `\n$& `) | |
.replace(regexSpace, ` $&`) | |
.replace(regexDoubleSpace, ` `) | |
.split(/\n/) | |
.filter(Boolean) | |
.map(action => action.trim()) | |
.map(action => action.split(' ')) | |
.map(action => { | |
switch (action[0]){ | |
case 'M': | |
case 'm': | |
return [ | |
action[0], | |
action[1] / width, | |
action[2] / height, | |
] | |
case 'V': | |
case 'v': | |
return [ | |
action[0], | |
action[1] / height, | |
] | |
case 'H': | |
case 'h': | |
return [ | |
action[0], | |
action[1] / width, | |
] | |
case 'Z': | |
case 'z': | |
return [ | |
action[0], | |
] | |
default: | |
return action; | |
} | |
}) | |
.map(action => action.join(' ')) | |
.join(' ') | |
; | |
return out; | |
} | |
console.log( transformTwo( productMobile, 457, 457 ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment