Skip to content

Instantly share code, notes, and snippets.

@francisrstokes
Last active December 27, 2018 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisrstokes/54bb2941a99f8c8271f5deb6353ae9a8 to your computer and use it in GitHub Desktop.
Save francisrstokes/54bb2941a99f8c8271f5deb6353ae9a8 to your computer and use it in GitHub Desktop.
Arcsecond Article
const {
parse,
char,
many,
regex,
anythingExcept,
sepBy
} = require('arcsecond');
const joinedMany = parser => many (parser) .map(x => x.join(''));
const cell = joinedMany (anythingExcept (regex (/^[,\n]/)));
const cells = sepBy (char (',')) (cell);
const parser = sepBy (char ('\n')) (cells);
const data = `
1,React JS,"A declarative efficient and flexible JavaScript library for building user interfaces"
2,Vue.js,"Vue.js is a progressive incrementally-adoptable JavaScript framework for building UI on the web."
3,Angular,"One framework. Mobile & desktop."
4,ember.js,"Ember.js - A JavaScript framework for creating ambitious web applications"`;
console.log(
parse (parser) (data)
);
// -> [
// [ '' ],
// [ '1', 'React JS', '"A declarative efficient and flexible JavaScript library for building user interfaces"' ],
// [ '2', 'Vue.js', '"Vue.js is a progressive incrementally-adoptable JavaScript framework for building UI on the web."' ],
// [ '3', 'Angular', '"One framework. Mobile & desktop."' ],
// [ '4', 'ember.js', '"Ember.js - A JavaScript framework for creating ambitious web applications"' ],
// ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment