1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 01:17:29 -04:00
notes/node_modules/pipetteur/pipetteur.js

33 lines
775 B
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
var synesthesia = require('synesthesia');
var color = require('onecolor');
var pipetteur = function (str) {
if (typeof str !== 'string') {
throw new Error('pipetteur: Expected string input, got ' + typeof str);
}
var matches = [],
match,
lines;
// Match colors incrementally
while ((match = synesthesia.all.exec(str)) !== null) {
lines = str.slice(0, match.index).split('\n');
matches.push({
index: match.index,
line: lines.length,
column: lines[lines.length - 1].length + 1,
match: match[0],
color: color(match[0])
});
}
// Reset search indexes
synesthesia.all.lastIndex = 0;
return matches;
};
module.exports = pipetteur;