periodicjs.ext.asyncadmin
Version:
An authentication extension for periodicjs that uses passport to authenticate user sessions.
1,591 lines (1,399 loc) • 1.45 MB
JavaScript
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var json2html,
moment = require('moment'),
Moment = moment,
// querystring = require('querystring'),
merge = require('util-extend'),
pluralize = require('pluralize');
pluralize.addIrregularRule('category', 'categories');
// if (typeof module !== 'undefined' && module.exports) {
// json2html = require('node-json2html');
// }
// else {
json2html = require('./json2html');
// }
var get_attribute_tags = function (attributes) {
var returnHtml = ' ';
for (var key in attributes) {
returnHtml += ' ' + key + '="' + attributes[key] + '" ';
}
returnHtml += ' ';
return returnHtml;
};
var get_data_table_html = function (options) {
options = options || {};
options.table_head_attributes = options.table_head_attributes || {};
options.thead_attributes = options.thead_attributes || {};
options.tbody_attributes = options.tbody_attributes || {};
options.tfoot_attributes = options.tfoot_attributes || {};
var dataObj = options.data,
responsive_table = options.responsive_table,
table_attributes = merge({
class: 'ts-table ts-sort-table ts-table-padding-md ts-text-left ts-width-100 ts-text-xs '
}, options.table_head_attributes),
thead_attributes = merge({
class: 'ts-table-head'
}, options.thead_attributes),
tbody_attributes = merge({
class: 'ts-table-body'
}, options.tbody_attributes),
tfoot_attributes = merge({
class: 'ts-table-foot'
}, options.tfoot_attributes),
data_attributes = options.data_attributes,
thead = options.thead,
tbody = options.tbody,
tfoot = options.tfoot,
static_data = options.static_data || {},
custom_thead = options.custom_thead,
custom_tbody = options.custom_tbody,
custom_tfoot = options.custom_tfoot,
data_table_html = ' ';
if (responsive_table) {
data_table_html = '<div class=" ts-screensm-hidden ts-screenxs-hidden"> ';
}
data_table_html += '<table ' + get_attribute_tags(table_attributes) + ' >';
if (custom_thead) {
data_table_html += custom_thead;
}
else if (thead) {
data_table_html += '<thead ' + get_attribute_tags(thead_attributes) + ' ><tr>';
data_table_html += json2html.transform(data_attributes, thead);
data_table_html += '</tr></thead>';
}
if (custom_tbody) {
data_table_html += custom_tbody;
}
else if (tbody) {
data_table_html += '<tbody ' + get_attribute_tags(tbody_attributes) + ' >';
if (static_data) {
dataObj = dataObj.map(function (body_data) {
body_data.static_data = static_data;
return body_data;
});
}
data_table_html += json2html.transform(dataObj, tbody);
data_table_html += '</tbody>';
}
if (custom_tfoot) {
data_table_html += custom_tfoot;
}
else if (tfoot) {
data_table_html += '<tfoot ' + get_attribute_tags(tfoot_attributes) + ' ><tr><td>footer</td>';
data_table_html += '</tr></tfoot>';
}
data_table_html += '</table>';
if (responsive_table) {
data_table_html += '</div>';
data_table_html += '<div class="ts-screenmd-hidden ts-screenlg-hidden ts-screenxl-hidden ts-screenxx-hidden">';
dataObj.forEach(function (responsive_data_row, i) {
data_table_html += '<details class="ts-genericdoc">';
data_table_html += '<summary>';
data_table_html += options.responsive_collapse(responsive_data_row, i);
data_table_html += '</summary>';
if (options.responsive_expand) {
data_table_html += '<aside class="ts-text-xs">';
data_table_html += options.responsive_expand(responsive_data_row, i);
data_table_html += '</aside>';
}
data_table_html += '</details>';
});
data_table_html += '</div>';
}
return data_table_html;
};
var default_responsive_collapse = function (options) {
return function (data_item) {
var collapseName = (typeof options.getCollapseNameFunction === 'function') ? options.getCollapseNameFunction(data_item) : data_item.name;
var editlink = options.editlink.replace('|||_id|||', data_item._id);
var deletelink = options.deletelink.replace('|||_id|||', data_item._id);
var drcHTML = '<div class="ts-pull-right">';
drcHTML += '<a href="' + editlink + '" class="async-admin-ajax-link" data-ajax-href="' + editlink + '"><img src="/extensions/periodicjs.ext.asyncadmin/img/icons/doc_edit_three.svg" alt="edit" class="ts-icon async-admin-ajax-link" data-ajax-href="' + editlink + '"/></a>';
drcHTML += '<a class="ts-button-error-color ts-dialog-delete" data-href="' + deletelink + '" data-deleted-redirect-href="' + options.deleterefreshlink + '" ><img src="/extensions/periodicjs.ext.asyncadmin/img/icons/doc_delete.svg" class="ts-icon ts-dialog-delete" data-href="' + deletelink + '" data-deleted-redirect-href="' + options.deleterefreshlink + '" alt="delete" /></a>';
drcHTML += '</div>';
drcHTML += collapseName + ' <small class="ts-text-divider-text-color">(' + new Moment(data_item.createdat).format('MM/DD/YYYY hh:mm:ssa') + ')</small>';
return drcHTML;
};
};
var default_responsive_expand = function ( /* options */ ) {
return function (data_item) {
return '<pre class="ts-text-sm">' + JSON.stringify(data_item, null, 2) + '</pre>';
};
};
var default_thead = function ( /* options */ ) {
return {
tag: 'th',
html: '<span class="sort_tr sort_tr_${sortactive}" data-sortid="${sortid}" data-sortorder="${sortorder}" >${label}</span>'
};
};
var default_custom_tfoot = function (options) {
var colspan = options.colspan || 10,
currentlimit = options.currentlimit || 15,
currentpage = options.currentpage || 1,
genericdocsperpage = [{
'value': currentlimit,
'label': currentlimit
}, {
'value': '15',
'label': '15'
}, {
'value': '30',
'label': '30'
}, {
'value': '50',
'label': '50'
}, {
'value': '250',
'label': '250'
}, {
'value': '500',
'label': '500'
}, {
'value': options.count,
'label': options.count
}];
var returnHTML = '<tfoot class="ts-table-foot">';
returnHTML += '<tr>';
returnHTML += '<td class="ts-text-center" colspan="' + colspan + '">';
if (currentpage > 1) {
returnHTML += '<a class="search-filter-prev-page"> <span class="ts-text-text-primary-color ts-cursor-pointer">‹ prev</span></a> | ';
}
returnHTML += 'showing <select class="table-search-limit">';
genericdocsperpage.forEach(function (iperpage) {
returnHTML += '<option ';
if (currentlimit === iperpage.value) {
returnHTML += ' selected="selected" ';
}
returnHTML += ' value="' + iperpage.value + '"> ';
returnHTML += iperpage.label + '</option>';
});
returnHTML += '</select>';
returnHTML += ' of ' + options.count + ' total';
if (currentpage < options.pages) {
returnHTML += ' | <a class="search-filter-next-page"> <span class="ts-text-text-primary-color ts-cursor-pointer">next ›</span></a>';
}
returnHTML += '</td>';
returnHTML += '</tr>';
returnHTML += '</tfoot>';
return returnHTML;
};
var cms_default_responsive_collapse = function (options) {
var path_to_content = options.path_to_content || 'content',
defaultOptions = {
editlink: '/' + options.adminPath + '/' + path_to_content + '/' + options.model_name + '/|||_id|||/edit',
deletelink: '/' + options.adminPath + '/' + path_to_content + '/' + options.model_name + '/|||_id|||/delete',
deleterefreshlink: '/' + options.adminPath + '/' + path_to_content + '/' + pluralize.plural(options.model_name) + '/'
};
return function (data_item) {
var editlink = defaultOptions.editlink.replace('|||_id|||', data_item._id);
var deletelink = defaultOptions.deletelink.replace('|||_id|||', data_item._id);
var drcHTML = '<div class="ts-pull-right">';
drcHTML += '<a href="' + editlink + '" class="async-admin-ajax-link" data-ajax-href="' + editlink + '"><img src="/extensions/periodicjs.ext.asyncadmin/img/icons/doc_edit_three.svg" alt="edit" class="ts-icon async-admin-ajax-link" data-ajax-href="' + editlink + '"/></a>';
drcHTML += '<a class="ts-button-error-color ts-dialog-delete" data-href="' + deletelink + '" data-deleted-redirect-href="' + options.deleterefreshlink + '" ><img src="/extensions/periodicjs.ext.asyncadmin/img/icons/doc_delete.svg" class="ts-icon ts-dialog-delete" data-href="' + deletelink + '" data-deleted-redirect-href="' + defaultOptions.deleterefreshlink + '" alt="delete" /></a>';
drcHTML += '</div>';
drcHTML += data_item.name + ' <small class="ts-text-divider-text-color">(' + new Moment(data_item.createdat).format('MM/DD/YYYY hh:mm:ssa') + ')</small>';
return drcHTML;
};
};
var get_taxonomy_html = function (options) {
var path_to_content = options.path_to_content || 'content',
returnHTML = '',
display_tax_model_name = (options.tax_model_name === 'user') ? 'author' : options.tax_model_name;
if (options.generictaxomony && options.generictaxomony.length > 0) {
if (options.tax_model_name === 'attribute' || options.tax_model_name === 'parent') {
returnHTML += display_tax_model_name + ': ';
}
else {
returnHTML += pluralize.plural(display_tax_model_name) + ': ';
}
options.generictaxomony.forEach(function (generictax, i) {
var displaylink = generictax.title || generictax.name || generictax.username;
if (options.tax_model_name === 'attribute' || options.tax_model_name === 'parent') {
returnHTML += '<small class="ts-text-divider-text-color" >' + displaylink + '</small> ';
}
else {
returnHTML += '<a class="async-admin-ajax-link" href="/' + options.adminPath + '/' + path_to_content + '/' + options.tax_model_name + '/' + generictax._id + '/edit">' + displaylink + '</a> ';
}
if (i !== (options.generictaxomony.length - 1)) {
returnHTML += ' , ';
}
});
}
return returnHTML;
};
var get_assets_html = function (options) {
var returnHTML = '';
if (options.genericassets && options.genericassets.length > 0) {
returnHTML += '<div>';
options.genericassets.forEach(function (genericasset) {
returnHTML += '<span class="ts-padding-md">';
// returnHTML+='<figure>';
// image79
// lock72 - keyhole lock74
// zipped2 - zip
if (genericasset.attributes && genericasset.attributes.encrypted_client_side) {
returnHTML += '<span class="ts-button flaticon-file82 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('audio')) {
returnHTML += '<span class="ts-button flaticon-audio55 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('music')) {
returnHTML += '<span class="ts-button flaticon-music232 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('application') || genericasset.assettype && genericasset.assettype.match('javascript') || genericasset.assettype && genericasset.assettype.match('css')) {
returnHTML += '<span class="ts-button flaticon-code41 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('video')) {
returnHTML += '<span class="ts-button flaticon-video170 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('word')) {
returnHTML += '<span class="ts-button flaticon-word6 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('excel')) {
returnHTML += '<span class="ts-button flaticon-x16 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('zip')) {
returnHTML += '<span class="ts-button flaticon-compressed1 ts-text-xx"></span>';
}
else if (genericasset.assettype && genericasset.assettype.match('image')) {
returnHTML += '<img style="max-width:4em; max-height:4em;" src="' + genericasset.fileurl + '"/>';
}
else if (genericasset.assettype && genericasset.assettype.match('text')) {
returnHTML += '<span class="ts-button flaticon-text140 ts-text-xx"></span>';
}
else {
returnHTML += '<span class="ts-button flaticon-file87 ts-text-xx"></span>';
}
//delete - recycle70
//edit - write19
// returnHTML+='<caption>'+ genericasset.title +'</caption>';
// returnHTML+='</figure>';
});
returnHTML += '</div>';
}
return returnHTML;
};
var cms_default_tbody = function (options) {
var path_to_content = options.path_to_content || 'content',
jsontableobj = {};
jsontableobj = {
tag: 'tr',
style: 'vertical-align:top;',
html: function (obj /*,i*/ ) {
var displayname = obj.title || obj.name || obj._id;
if (obj.attributes && obj.attributes.encrypted_client_side) {
displayname += ' <i class="flaticon-access1 ts-text-xs ts-button-icon"></i>';
}
var jsontablehtml;
jsontablehtml = '<td>';
jsontablehtml += '<a href="/' + options.adminPath + '/' + path_to_content + '/' + options.model_name + '/' + obj._id + '/edit" class="async-admin-ajax-link">' + displayname + '</a>';
jsontablehtml += '</td>';
//create date
jsontablehtml += '<td>' + new Moment(obj.createdat).format('MM/DD/YYYY | hh:mm:ssa') + '</td>';
//authors
options.generictaxomony = obj.authors;
options.tax_model_name = 'user';
jsontablehtml += '<td>' + get_taxonomy_html(options);
//assets
if (options.model_name === 'asset') {
jsontablehtml += get_assets_html({
genericassets: [obj]
});
}
//contenttypes
options.generictaxomony = obj.contenttypes;
options.tax_model_name = 'contenttype';
jsontablehtml += get_taxonomy_html(options);
//tags
options.generictaxomony = obj.tags;
options.tax_model_name = 'tag';
jsontablehtml += get_taxonomy_html(options);
//categories
options.generictaxomony = obj.categories;
options.tax_model_name = 'category';
jsontablehtml += get_taxonomy_html(options);
//attributes
options.generictaxomony = obj.attributes;
options.tax_model_name = 'attribute';
jsontablehtml += get_taxonomy_html(options);
//parent
options.generictaxomony = obj.parent;
options.tax_model_name = 'parent';
jsontablehtml += get_taxonomy_html(options);
jsontablehtml += get_assets_html({
genericassets: obj.assets
});
jsontablehtml += '</td>';
//options
jsontablehtml += '<td> <a href="/' + options.adminPath + '/' + path_to_content + '/' + options.model_name + '/' + obj._id + '/edit" class="async-admin-ajax-link flaticon-write19 ts-button-icon ts-button"></a> ';
jsontablehtml += '<a class="ts-button-error-color ts-dialog-delete flaticon-recycle70 ts-button-icon ts-button" data-href="/' + options.adminPath + '/' + path_to_content + '/' + options.model_name + '/' + obj._id + '/delete" data-deleted-redirect-href="/' + options.adminPath + '/' + path_to_content + '/' + pluralize.plural(options.model_name) + '"/></a></td>';
return jsontablehtml;
}
};
return jsontableobj;
};
exports.cms_default_tbody = cms_default_tbody;
exports.cms_default_responsive_collapse = cms_default_responsive_collapse;
exports.default_responsive_collapse = default_responsive_collapse;
exports.default_responsive_expand = default_responsive_expand;
exports.default_thead = default_thead;
exports.default_custom_tfoot = default_custom_tfoot;
exports.get_data_table_html = get_data_table_html;
},{"./json2html":2,"moment":83,"pluralize":91,"util-extend":125}],2:[function(require,module,exports){
'use strict';
//Copyright (c) 2013 Crystalline Technologies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
var json2html = {
/* ---------------------------------------- Public Methods ------------------------------------------------ */
'transform': function (json, transform, _options) {
//create the default output
var out = {
'events': [],
'html': ''
};
//default options (by default we don't allow events)
var options = {
'events': false
};
//extend the options
options = json2html._extend(options, _options);
//Make sure we have a transform & json object
if (transform !== undefined || json !== undefined) {
//Normalize strings to JSON objects if necessary
var obj = typeof json === 'string' ? JSON.parse(json) : json;
//Transform the object (using the options)
out = json2html._transform(obj, transform, options);
}
//determine if we need the events
// otherwise return just the html string
if (options.events) return (out);
else return (out.html);
},
/* ---------------------------------------- Private Methods ------------------------------------------------ */
//Extend options
'_extend': function (obj1, obj2) {
var obj3 = {};
for (var attrname in obj1) {
obj3[attrname] = obj1[attrname];
}
for (var attrname in obj2) {
obj3[attrname] = obj2[attrname];
}
return obj3;
},
//Append results
'_append': function (obj1, obj2) {
var out = {
'html': '',
'event': []
};
if (typeof obj1 !== 'undefined' && typeof obj2 !== 'undefined') {
out.html = obj1.html + obj2.html;
out.events = obj1.events.concat(obj2.events);
}
return (out);
},
//isArray (fix for IE prior to 9)
'_isArray': function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
},
//Transform object
'_transform': function (json, transform, options) {
var elements = {
'events': [],
'html': ''
};
//Determine the type of this object
if (json2html._isArray(json)) {
//Itterrate through the array and add it to the elements array
var len = json.length;
for (var j = 0; j < len; ++j) {
//Apply the transform to this object and append it to the results
elements = json2html._append(elements, json2html._apply(json[j], transform, j, options));
}
}
else if (typeof json === 'object') {
//Apply the transform to this object and append it to the results
elements = json2html._append(elements, json2html._apply(json, transform, undefined, options));
}
//Return the resulting elements
return (elements);
},
//Apply the transform at the second level
'_apply': function (obj, transform, index, options) {
var element = {
'events': [],
'html': ''
};
//Itterate through the transform and create html as needed
if (json2html._isArray(transform)) {
var t_len = transform.length;
for (var t = 0; t < t_len; ++t) {
//transform the object and append it to the output
element = json2html._append(element, json2html._apply(obj, transform[t], index, options));
}
}
else if (typeof transform === 'object') {
//Get the tag element of this transform
if (transform.tag !== undefined) {
var tag = json2html._getValue(obj, transform, 'tag', index);
//Create a new element
element.html += '<' + tag;
//Create a new object for the children
var children = {
'events': [],
'html': ''
};
//innerHTML
var html;
//Look into the properties of this transform
for (var key in transform) {
switch (key) {
case 'tag':
//Do nothing as we have already created the element from the tag
break;
case 'children':
//Add the children
if (json2html._isArray(transform.children)) {
//Apply the transform to the children
children = json2html._append(children, json2html._apply(obj, transform.children, index, options));
}
else if (typeof transform.children === 'function') {
//Get the result from the function
var temp = transform.children.call(obj, obj, index);
//Make sure we have an object result with the props
// html (string), events (array)
// OR a string (then just append it to the children
if (typeof temp === 'object') {
//make sure this object is a valid json2html response object
if (temp.html !== undefined && temp.events !== undefined) children = json2html._append(children, temp);
}
else if (typeof temp === 'string') {
//append the result directly to the html of the children
children.html += temp;
}
}
break;
case 'html':
//Create the html attribute for this element
html = json2html._getValue(obj, transform, 'html', index);
break;
default:
//Add the property as a attribute if it's not a key one
var isEvent = false;
//Check if the first two characters are 'on' then this is an event
if (key.length > 2)
if (key.substring(0, 2).toLowerCase() == 'on') {
//Determine if we should add events
if (options.events) {
//if so then setup the event data
var data = {
'action': transform[key],
'obj': obj,
'data': options.eventData,
'index': index
};
//create a new id for this event
var id = json2html._guid();
//append the new event to this elements events
element.events[element.events.length] = {
'id': id,
'type': key.substring(2),
'data': data
};
//Insert temporary event property (json2html-event-id) into the element
element.html += " json2html-event-id-" + key.substring(2) + "='" + id + "'";
}
//this is an event
isEvent = true;
}
//If this wasn't an event AND we actually have a value then add it as a property
if (!isEvent) {
//Get the value
var val = json2html._getValue(obj, transform, key, index);
//Make sure we have a value
if (val !== undefined) {
var out;
//Determine the output type of this value (wrap with quotes)
if (typeof val === 'string') out = '"' + val.replace(/"/g, '"') + '"';
else out = val;
//creat the name value pair
element.html += ' ' + key + '=' + out;
}
}
break;
}
}
//close the opening tag
element.html += '>';
//add the innerHTML (if we have any)
if (html) element.html += html;
//add the children (if we have any)
element = json2html._append(element, children);
//add the closing tag
element.html += '</' + tag + '>';
}
}
//Return the output object
return (element);
},
//Get a new GUID (used by events)
'_guid': function () {
var S4 = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return (S4() + S4() + "-" + S4() + S4() + "-" + S4() + S4());
},
//Get the html value of the object
'_getValue': function (obj, transform, key, index) {
var out = '';
var val = transform[key];
var type = typeof val;
if (type === 'function') {
return (val.call(obj, obj, index));
}
else if (type === 'string') {
var _tokenizer = new json2html._tokenizer([
/\$\{([^\}\{]+)\}/
], function (src, real, re) {
return real ? src.replace(re, function (all, name) {
//Split the string into it's seperate components
var components = name.split('.');
//Set the object we use to query for this name to be the original object
var useObj = obj;
//Output value
var outVal = '';
//Parse the object components
var c_len = components.length;
for (var i = 0; i < c_len; ++i) {
if (components[i].length > 0) {
var newObj = useObj[components[i]];
useObj = newObj;
if (useObj === null || useObj === undefined) break;
}
}
//As long as we have an object to use then set the out
if (useObj !== null && useObj !== undefined) outVal = useObj;
return (outVal);
}) : src;
});
out = _tokenizer.parse(val).join('');
}
else {
out = val;
}
return (out);
},
//Tokenizer
'_tokenizer': function (tokenizers, doBuild) {
if (!(this instanceof json2html._tokenizer))
return new json2html._tokenizer(tokenizers, doBuild);
this.tokenizers = tokenizers.splice ? tokenizers : [tokenizers];
if (doBuild)
this.doBuild = doBuild;
this.parse = function (src) {
this.src = src;
this.ended = false;
this.tokens = [];
do {
this.next();
} while (!this.ended);
return this.tokens;
};
this.build = function (src, real) {
if (src)
this.tokens.push(!this.doBuild ? src :
this.doBuild(src, real, this.tkn)
);
};
this.next = function () {
var self = this,
plain;
self.findMin();
plain = self.src.slice(0, self.min);
self.build(plain, false);
self.src = self.src.slice(self.min).replace(self.tkn, function (all) {
self.build(all, true);
return '';
});
if (!self.src)
self.ended = true;
};
this.findMin = function () {
var self = this,
i = 0,
tkn, idx;
self.min = -1;
self.tkn = '';
while ((tkn = self.tokenizers[i++]) !== undefined) {
idx = self.src[tkn.test ? 'search' : 'indexOf'](tkn);
if (idx != -1 && (self.min == -1 || idx < self.min)) {
self.tkn = tkn;
self.min = idx;
}
}
if (self.min == -1)
self.min = self.src.length;
};
}
};
module.exports = json2html;
},{}],3:[function(require,module,exports){
module.exports = after
function after(count, callback, err_cb) {
var bail = false
err_cb = err_cb || noop
proxy.count = count
return (count === 0) ? callback() : proxy
function proxy(err, result) {
if (proxy.count <= 0) {
throw new Error('after called too many times')
}
--proxy.count
// after first error, rest are passed to err_cb
if (err) {
bail = true
callback(err)
// future error callbacks will go to error handler
callback = err_cb
} else if (proxy.count === 0 && !bail) {
callback(null, result)
}
}
}
function noop() {}
},{}],4:[function(require,module,exports){
/**
* An abstraction for slicing an arraybuffer even when
* ArrayBuffer.prototype.slice is not supported
*
* @api public
*/
module.exports = function(arraybuffer, start, end) {
var bytes = arraybuffer.byteLength;
start = start || 0;
end = end || bytes;
if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
if (start < 0) { start += bytes; }
if (end < 0) { end += bytes; }
if (end > bytes) { end = bytes; }
if (start >= bytes || start >= end || bytes === 0) {
return new ArrayBuffer(0);
}
var abv = new Uint8Array(arraybuffer);
var result = new Uint8Array(end - start);
for (var i = start, ii = 0; i < end; i++, ii++) {
result[ii] = abv[i];
}
return result.buffer;
};
},{}],5:[function(require,module,exports){
(function (process,global){
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.async = global.async || {})));
}(this, function (exports) { 'use strict';
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {Array} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
var length = args.length;
switch (length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
var funcTag = '[object Function]';
var genTag = '[object GeneratorFunction]';
/** Used for built-in method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString = objectProto.toString;
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 8 which returns 'object' for typed array and weak map constructors,
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
var tag = isObject(value) ? objectToString.call(value) : '';
return tag == funcTag || tag == genTag;
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
}
/** `Object#toString` result references. */
var symbolTag = '[object Symbol]';
/** Used for built-in method references. */
var objectProto$1 = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString$1 = objectProto$1.toString;
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(isObjectLike(value) && objectToString$1.call(value) == symbolTag);
}
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3.2);
* // => 3.2
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3.2');
* // => 3.2
*/
function toNumber(value) {
if (typeof value == 'number') {
return value;
}
if (isSymbol(value)) {
return NAN;
}
if (isObject(value)) {
var other = isFunction(value.valueOf) ? value.valueOf() : value;
value = isObject(other) ? (other + '') : other;
}
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = value.replace(reTrim, '');
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: (reIsBadHex.test(value) ? NAN : +value);
}
var INFINITY = 1 / 0;
var MAX_INTEGER = 1.7976931348623157e+308;
/**
* Converts `value` to a finite number.
*
* @static
* @memberOf _
* @since 4.12.0
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted number.
* @example
*
* _.toFinite(3.2);
* // => 3.2
*
* _.toFinite(Number.MIN_VALUE);
* // => 5e-324
*
* _.toFinite(Infinity);
* // => 1.7976931348623157e+308
*
* _.toFinite('3.2');
* // => 3.2
*/
function toFinite(value) {
if (!value) {
return value === 0 ? value : 0;
}
value = toNumber(value);
if (value === INFINITY || value === -INFINITY) {
var sign = (value < 0 ? -1 : 1);
return sign * MAX_INTEGER;
}
return value === value ? value : 0;
}
/**
* Converts `value` to an integer.
*
* **Note:** This method is loosely based on
* [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted integer.
* @example
*
* _.toInteger(3.2);
* // => 3
*
* _.toInteger(Number.MIN_VALUE);
* // => 0
*
* _.toInteger(Infinity);
* // => 1.7976931348623157e+308
*
* _.toInteger('3.2');
* // => 3
*/
function toInteger(value) {
var result = toFinite(value),
remainder = result % 1;
return result === result ? (remainder ? result - remainder : result) : 0;
}
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* Creates a function that invokes `func` with the `this` binding of the
* created function and arguments from `start` and beyond provided as
* an array.
*
* **Note:** This method is based on the
* [rest parameter](https://mdn.io/rest_parameters).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Function
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @returns {Function} Returns the new function.
* @example
*
* var say = _.rest(function(what, names) {
* return what + ' ' + _.initial(names).join(', ') +
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
* });
*
* say('hello', 'fred', 'barney', 'pebbles');
* // => 'hello fred, barney, & pebbles'
*/
function rest(func, start) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
return function() {
var args = arguments,
index = -1,
length = nativeMax(args.length - start, 0),
array = Array(length);
while (++index < length) {
array[index] = args[start + index];
}
switch (start) {
case 0: return func.call(this, array);
case 1: return func.call(this, args[0], array);
case 2: return func.call(this, args[0], args[1], array);
}
var otherArgs = Array(start + 1);
index = -1;
while (++index < start) {
otherArgs[index] = args[index];
}
otherArgs[start] = array;
return apply(func, this, otherArgs);
};
}
function initialParams (fn) {
return rest(function (args /*..., callback*/) {
var callback = args.pop();
fn.call(this, args, callback);
});
}
function applyEach$1(eachfn) {
return rest(function (fns, args) {
var go = initialParams(function (args, callback) {
var that = this;
return eachfn(fns, function (fn, cb) {
fn.apply(that, args.concat([cb]));
}, callback);
});
if (args.length) {
return go.apply(this, args);
} else {
return go;
}
});
}
/**
* A method that returns `undefined`.
*
* @static
* @memberOf _
* @since 2.3.0
* @category Util
* @example
*
* _.times(2, _.noop);
* // => [undefined, undefined]
*/
function noop() {
// No operation performed.
}
function once(fn) {
return function () {
if (fn === null) return;
var callFn = fn;
fn = null;
callFn.apply(this, arguments);
};
}
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new accessor function.
*/
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
/**
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a
* [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
* Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
var getLength = baseProperty('length');
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is loosely based on
* [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length,
* else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null && isLength(getLength(value)) && !isFunction(value);
}
var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator;
function getIterator (coll) {
return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol]();
}
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetPrototype = Object.getPrototypeOf;
/**
* Gets the `[[Prototype]]` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {null|Object} Returns the `[[Prototype]]`.
*/
function getPrototype(value) {
return nativeGetPrototype(Object(value));
}
/** Used for built-in method references. */
var objectProto$2 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto$2.hasOwnProperty;
/**
* The base implementation of `_.has` without support for deep paths.
*
* @private
* @param {Object} [object] The object to query.
* @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHas(object, key) {
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
// that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them.
return object != null &&
(hasOwnProperty.call(object, key) ||
(typeof object == 'object' && key in object && getPrototype(object) === null));
}
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeKeys = Object.keys;
/**
* The base implementation of `_.keys` which doesn't skip the constructor
* property of prototypes or treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
return nativeKeys(Object(object));
}
/**
* The base implementation of `_.times` without support for iteratee shorthands
* or max array length checks.
*
* @private
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the array of results.
*/
function baseTimes(n, iteratee) {
var index = -1,
result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
/**
* This method is like `_.isArrayLike` except that it also checks if `value`
* is an object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array-like object,
* else `false`.
* @example
*
* _.isArrayLikeObject([1, 2, 3]);
* // => true
*
* _.isArrayLikeObject(document.body.children);
* // => true
*
* _.isArrayLikeObject('abc');
* // => false
*
* _.isArrayLikeObject(_.noop);
* // => false
*/
function isArrayLikeObject(value) {
return isObjectLike(value) && isArrayLike(value);
}
/** `Object#toString` result references. */
var argsTag = '[object Arguments]';
/** Used for built-in method references. */
var objectProto$3 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$1 = objectProto$3.hasOwnProperty;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString$2 = objectProto$3.toString;
/** Built-in value references. */
var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
/**
* Checks if `value` is likely an `arguments` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
function isArguments(value) {
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
return isArrayLikeObject(value) && hasOwnProperty$1.call(value, 'callee') &&
(!propertyIsEnumerable.call(value, 'callee') || objectToString$2.call(value) == argsTag);
}
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @type {Function}
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
/** `Object#toString` result references. */
var stringTag = '[object String]';
/** Used for built-in method references. */
var objectProto$4 = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString$3 = objectProto$4.toString;
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isString('abc');
* // => true
*
* _.isString(1);
* // => false
*/
function isString(value) {
return typeof value == 'string' ||
(!isArray(value) && isObjectLike(value) && objectToString$3.call(value) == stringTag);
}
/**
* Creates an array of index keys for `object` values of arrays,
* `arguments` objects, and strings, otherwise `null` is returned.
*
* @private
* @param {Object} object The object to query.
* @returns {Array|null} Returns index keys, else `null`.
*/
function indexKeys(object) {
var length = object ? object.length : undefined;
if (isLength(length) &&
(isArray(object) || isString(object) || isArguments(object))) {
return baseTimes(length, String);
}
return null;
}
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER$1 = 9007199254740991;
/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
length = length == null ? MAX_SAFE_INTEGER$1 : length;
return !!length &&
(typeof value == 'number' || reIsUint.test(value)) &&
(value > -1 && value % 1 == 0 && value < length);
}
/** Used for built-in method references. */
var objectProto$5 = Object.prototype;
/**
* Checks if `value` is likely a prototype object.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
*/
function isPrototype(value) {
var Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5;
return value === proto;
}
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
* for mor