Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What if javascript had printf - pdo-style api
// @todo wishlist - isomorphic node-style error handling
const traverse = function() {}
const iterate = (arr) => {
const arr = arr;
const pos = 0;
const next = () => {}
const cont = () => {}
const end = () => {}
const prev = () => {}
const rewind = () => {}
const first = () => {}
const map = (fn, ...args) => {
fn.apply(this, ...args);
}
const filter = (arr) => {}
return {
next,
cont,
end,
prev,
rewind,
first
}
}
/**
*
* @param {String} string
* @param {Object} data
*/
const Preparation = function(statement, data) {
if (typeof statement !== 'string') {
throw new Error('Invalid argument type')
}
if (typeof data !== 'object' || !Array.isArray(data)) {
throw new Error('Invalid argument type')
}
let preparation = this.init();
// let's use a closure so that we can
// reuse the `init` and `prepare` function whenever we need to
preparation.call(this, statement)
}
/**
*
* @return {function}
*/
Preparation.prototype.init = function init() {
// one time init logic
return function(statement) {
// re-init logic
this.setStatement(statement)
}
}
Preparation.prototype.getStatement = function getStatement() {
if (!this.statement) {
//
}
return this.statement;
}
/**
* @chainable
* @param {String} statement
* @return Preparation
*/
Preparation.prototype.setStatement = function setStatement(statement) {
this.statement = statement;
return this;
};
const parse = function() => {
const map = (statement) => {
if (!statement) {
let statement = this.getStatement()
}
if (!statement) {
throw new Error('Unexpected Error')
}
if (typeof statement !== 'string') {
throw new Error('Invalid argument type')
}
iterate(statement).map(parse);
}
const parse = (character) => {
}
return {
map,
parse
}
}
Preparation.prototype.findObjectIndex = function findObjectIndex() {
};
//
let prepare = new Preparation('The name of the %1', {
name: 'universe'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.