1
0
mirror of https://github.com/thangisme/notes.git synced 2024-12-22 15:36:36 -05:00
notes/node_modules/pipetteur/pipetteur.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

33 lines
775 B
JavaScript

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;