Skip to content

Instantly share code, notes, and snippets.

@snowkidind
Created December 17, 2017 19:33
Show Gist options
  • Save snowkidind/c1c0a8bc2c45cdbbf359168eab0c0bb2 to your computer and use it in GitHub Desktop.
Save snowkidind/c1c0a8bc2c45cdbbf359168eab0c0bb2 to your computer and use it in GitHub Desktop.
// returns a string that is formatted for search indexes
toFormat: function(raw){
// reality here is that the query should find both ways
raw = String(raw);
raw = raw.replace(/ /g, '');
raw = raw.replace(/_/g, ''); // liqui
raw = raw.replace(/\//g, '');
// assert string
raw = String(raw);
// check string length for (only three characters, if so default btc)
if (raw.length < 6){
// a pair has not been provided, this is either a single token or noise.
// does it contain btc eth or usdt?
// if not add btc, else err
if (!raw.includes("BTC") || !raw.includes("ETH") || !raw.includes("USDT")){
raw = raw + "BTC";
}
return raw.replace(/-/g, "").toUpperCase();
}
else {
// remove any dashes
const raw1 = raw.replace(/-/g, "");
// make uppercase
return raw2 = raw1.toUpperCase();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment