pantoninho/file-interpolator

View on GitHub
src/stream/interpolator.js

Summary

Maintainability
A
0 mins
Test Coverage
var stream = require('./index');

module.exports = function(data, matches) {

    var lastCharIndex, dataStream, streams;

    streams = [];

    lastCharIndex = matches.reduce(function(currentCharIndex, match) {

        dataStream = stream.fromString(data.substring(currentCharIndex, match.at));
        streams.push(dataStream);

        streams.push(match.stream);

        return match.at + match.marker.length;
    }, 0);

    dataStream = stream.fromString(data.substring(lastCharIndex));
    streams.push(dataStream);

    return streams;
};