code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function View (req, res) {
if (!req || req.constructor.name !== 'IncomingMessage') {
throw new Error('Keystone.View Error: Express request object is required.');
}
if (!res || res.constructor.name !== 'ServerResponse') {
throw new Error('Keystone.View Error: Express response object is required.');
}
this.re... | View Constructor
=================
Helper to simplify view logic in a Keystone application
@api public | View | javascript | keystonejs/keystone-classic | lib/view.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/view.js | MIT |
check = function (value, path) {
var ctx = req;
var parts = path.split('.');
for (var i = 0; i < parts.length - 1; i++) {
if (!ctx[parts[i]]) {
return false;
}
ctx = ctx[parts[i]];
}
path = _.last(parts);
return (value === true && path in ctx) ? true : (ctx[path] === value);
} | Adds a method (or array of methods) to be executed in parallel
to the `init`, `action` or `render` queue.
@api public | check | javascript | keystonejs/keystone-classic | lib/view.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/view.js | MIT |
QueryCallbacks = function (options) {
if (utils.isString(options)) {
options = { then: options };
} else {
options = options || {};
}
this.callbacks = {};
if (options.err) this.callbacks.err = options.err;
if (options.none) this.callbacks.none = options.none;
if (options.then) this.callbacks.then = options.t... | Adds a method (or array of methods) to be executed in parallel
to the `init`, `action` or `render` queue.
@api public | QueryCallbacks | javascript | keystonejs/keystone-classic | lib/view.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/view.js | MIT |
function Page (key, options) {
if (!(this instanceof Page)) {
return new Page(key, options);
}
this.options = assign({}, options);
this.key = key;
this.fields = {};
} | Page Class
@param {String} key
@param {Object} options
@api public | Page | javascript | keystonejs/keystone-classic | lib/content/page.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/content/page.js | MIT |
function html (path, options) {
html.super_.call(path, options);
} | HTML ContentType Constructor
@extends Field
@api public | html | javascript | keystonejs/keystone-classic | lib/content/types/html.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/content/types/html.js | MIT |
function text (path, options) {
text.super_.call(path, options);
} | Text ContentType Constructor
@extends Field
@api public | text | javascript | keystonejs/keystone-classic | lib/content/types/text.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/content/types/text.js | MIT |
function isMongoId (value) {
return MONGO_ID_REGEXP.test(value);
} | Creates multiple items in one or more Lists | isMongoId | javascript | keystonejs/keystone-classic | lib/core/createItems.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/createItems.js | MIT |
function createItems (data, ops, callback) {
var keystone = this;
var options = {
verbose: false,
strict: true,
refs: null,
};
var dashes = '------------------------------------------------';
if (!_.isObject(data)) {
throw new Error('keystone.createItems() requires a data object as the first argument.'... | Creates multiple items in one or more Lists | createItems | javascript | keystonejs/keystone-classic | lib/core/createItems.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/createItems.js | MIT |
function writeLog (data) {
console.log(keystone.get('name') + ': ' + data);
} | Creates multiple items in one or more Lists | writeLog | javascript | keystonejs/keystone-classic | lib/core/createItems.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/createItems.js | MIT |
function getOrphanedLists () {
if (!this.nav) {
return [];
}
return _.filter(this.lists, function (list, key) {
if (list.get('hidden')) return false;
return (!this.nav.by.list[key]) ? list : false;
}.bind(this));
} | Retrieves orphaned lists (those not in a nav section) | getOrphanedLists | javascript | keystonejs/keystone-classic | lib/core/getOrphanedLists.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/getOrphanedLists.js | MIT |
function dispatchImporter (rel__dirname) {
function importer (from) {
debug('importing ', from);
var imported = {};
var joinPath = function () {
return '.' + path.sep + path.join.apply(path, arguments);
};
var fsPath = joinPath(path.relative(process.cwd(), rel__dirname), from);
fs.readdirSync(fsPath).... | Returns a function that looks in a specified path relative to the current
directory, and returns all .js modules in it (recursively).
####Example:
var importRoutes = keystone.importer(__dirname);
var routes = {
site: importRoutes('./site'),
api: importRoutes('./api')
};
@param {String} r... | dispatchImporter | javascript | keystonejs/keystone-classic | lib/core/importer.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/importer.js | MIT |
function importer (from) {
debug('importing ', from);
var imported = {};
var joinPath = function () {
return '.' + path.sep + path.join.apply(path, arguments);
};
var fsPath = joinPath(path.relative(process.cwd(), rel__dirname), from);
fs.readdirSync(fsPath).forEach(function (name) {
var info = fs.st... | Returns a function that looks in a specified path relative to the current
directory, and returns all .js modules in it (recursively).
####Example:
var importRoutes = keystone.importer(__dirname);
var routes = {
site: importRoutes('./site'),
api: importRoutes('./api')
};
@param {String} r... | importer | javascript | keystonejs/keystone-classic | lib/core/importer.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/importer.js | MIT |
joinPath = function () {
return '.' + path.sep + path.join.apply(path, arguments);
} | Returns a function that looks in a specified path relative to the current
directory, and returns all .js modules in it (recursively).
####Example:
var importRoutes = keystone.importer(__dirname);
var routes = {
site: importRoutes('./site'),
api: importRoutes('./api')
};
@param {String} r... | joinPath | javascript | keystonejs/keystone-classic | lib/core/importer.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/importer.js | MIT |
function init (options) {
this.options(options);
return this;
} | Initialises Keystone with the provided options | init | javascript | keystonejs/keystone-classic | lib/core/init.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/init.js | MIT |
function isAbsolutePath (value) {
return path.resolve(value) === path.normalize(value).replace(new RegExp(path.sep + '$'), '');
} | This file contains methods specific to dealing with Keystone's options.
All exports are added to the Keystone.prototype | isAbsolutePath | javascript | keystonejs/keystone-classic | lib/core/options.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/options.js | MIT |
function redirect () {
if (arguments.length === 1 && utils.isObject(arguments[0])) {
_.extend(this._redirects, arguments[0]);
} else if (arguments.length === 2 && typeof arguments[0] === 'string' && typeof arguments[1] === 'string') {
this._redirects[arguments[0]] = arguments[1];
}
return this;
} | Adds one or more redirections (urls that are redirected when no matching
routes are found, before treating the request as a 404)
#### Example:
keystone.redirect('/old-route', 'new-route');
// or
keystone.redirect({
'old-route': 'new-route'
}); | redirect | javascript | keystonejs/keystone-classic | lib/core/redirect.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/redirect.js | MIT |
function start (events) {
if (typeof events === 'function') {
events = { onStart: events };
}
if (!events) events = {};
function fireEvent (name) {
if (typeof events[name] === 'function') {
events[name]();
}
}
process.on('uncaughtException', function (e) {
if (e.code === 'EADDRINUSE') {
console.l... | Configures and starts a Keystone app in encapsulated mode.
Connects to the database, runs updates and listens for incoming requests.
Events are fired during initialisation to allow customisation, including:
- onMount
- onStart
- onHttpServerCreated
- onHttpsServerCreated
If the events argument is a function... | start | javascript | keystonejs/keystone-classic | lib/core/start.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/start.js | MIT |
function fireEvent (name) {
if (typeof events[name] === 'function') {
events[name]();
}
} | Configures and starts a Keystone app in encapsulated mode.
Connects to the database, runs updates and listens for incoming requests.
Events are fired during initialisation to allow customisation, including:
- onMount
- onStart
- onHttpServerCreated
- onHttpsServerCreated
If the events argument is a function... | fireEvent | javascript | keystonejs/keystone-classic | lib/core/start.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/start.js | MIT |
function wrapHTMLError (title, err) {
return '<html><head><meta charset=\'utf-8\'><title>Error</title>'
+ '<link rel=\'stylesheet\' href=\'/' + this.get('admin path') + '/styles/error.css\'>'
+ '</head><body><div class=\'error\'><h1 class=\'error-title\'>' + title + '</h1>'
+ '<div class="error-message">' + (err ||... | Wraps an error in simple HTML to be sent as a response to the browser
@api public | wrapHTMLError | javascript | keystonejs/keystone-classic | lib/core/wrapHTMLError.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/core/wrapHTMLError.js | MIT |
function add () {
var add = function (obj, prefix) {
prefix = prefix || '';
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (!obj[key]) {
throw new Error(
'Invalid value for schema path `' + prefix + key + '` in `' + this.key + '`.\n'
+ 'Did you miss... | Adds one or more fields to the List
Based on Mongoose's Schema.add | add | javascript | keystonejs/keystone-classic | lib/list/add.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/add.js | MIT |
function automap (field) {
if ((field.path in this.mappings) && !this.mappings[field.path]) {
this.map(field.path, field.path);
}
return this;
} | Checks to see if a field path matches a currently unmapped path, and
if so, adds a mapping for it. | automap | javascript | keystonejs/keystone-classic | lib/list/automap.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/automap.js | MIT |
function buildSearchTextIndex () {
var idxDef = {};
for (var i = 0; i < this.searchFields.length; i++) {
var sf = this.searchFields[i];
if (!sf.path || !sf.field) continue;
// TODO: Allow fields to define their own `getTextIndex` method, so that
// each type can define the right options for their schema. Th... | Returns either false if the list has no search fields defined or a structure
describing the text index that should exist. | buildSearchTextIndex | javascript | keystonejs/keystone-classic | lib/list/buildSearchTextIndex.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/buildSearchTextIndex.js | MIT |
function declaresTextIndex () {
var indexes = this.schema.indexes();
for (var i = 0; i < indexes.length; i++) {
var fields = indexes[i][0];
var fieldNames = Object.keys(fields);
for (var h = 0; h < fieldNames.length; h++) {
var val = fields[fieldNames[h]];
if (typeof val === 'string' && val.toLowerCase(... | Look for a text index defined in the current list schema; returns boolean
Note this doesn't check for text indexes that exist in the DB | declaresTextIndex | javascript | keystonejs/keystone-classic | lib/list/declaresTextIndex.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/declaresTextIndex.js | MIT |
function ensureTextIndex (callback) {
var list = this;
var collection = list.model.collection;
var textIndex = list.buildSearchTextIndex();
var fieldsHash = Math.abs(hashString(Object.keys(textIndex).sort().join(';')));
var indexNamePrefix = 'keystone_searchFields_textIndex_';
var newIndexName = indexNamePrefix ... | Does what it can to ensure the collection has an appropriate text index.
Works around unreliable behaviour with the Mongo drivers ensureIndex()
Specifically, when the following are true..
- Relying on collection.ensureIndexes() to create text indexes
- A text index already exists on the collection
- The existing... | ensureTextIndex | javascript | keystonejs/keystone-classic | lib/list/ensureTextIndex.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/ensureTextIndex.js | MIT |
createNewIndex = function () {
collection.createIndex(textIndex, { name: newIndexName }, function (result) {
debug('collection.createIndex() result for \'' + list.key + '\:', result);
return callback();
});
} | Does what it can to ensure the collection has an appropriate text index.
Works around unreliable behaviour with the Mongo drivers ensureIndex()
Specifically, when the following are true..
- Relying on collection.ensureIndexes() to create text indexes
- A text index already exists on the collection
- The existing... | createNewIndex | javascript | keystonejs/keystone-classic | lib/list/ensureTextIndex.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/ensureTextIndex.js | MIT |
function expandColumns (cols) {
if (typeof cols === 'string') {
cols = cols.split(',');
}
if (!Array.isArray(cols)) {
throw new Error('List.expandColumns: cols must be an array.');
}
var list = this;
var expanded = [];
var nameCol = false;
var getCol = function (def) {
if (def.path === '__name__') {
de... | Expands a comma-separated string or array of columns into valid column objects.
Columns can be:
- A Field, in the format "field|width"
- A Field in a single related List, in the format "list:field|width"
- Any valid path in the Schema, in the format "path|width"
The width part is optional, and can be in the ... | expandColumns | javascript | keystonejs/keystone-classic | lib/list/expandColumns.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/expandColumns.js | MIT |
getCol = function (def) {
if (def.path === '__name__') {
def.path = list.namePath;
}
var field = list.fields[def.path];
var col = null;
if (field) {
col = {
field: field,
path: field.path,
type: field.type,
label: def.label || field.label,
};
if (col.type === 'relationship') {
... | Expands a comma-separated string or array of columns into valid column objects.
Columns can be:
- A Field, in the format "field|width"
- A Field in a single related List, in the format "list:field|width"
- Any valid path in the Schema, in the format "path|width"
The width part is optional, and can be in the ... | getCol | javascript | keystonejs/keystone-classic | lib/list/expandColumns.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/expandColumns.js | MIT |
function field (path, options) {
var Field = this.keystone.Field;
if (arguments.length === 1) {
return this.fields[path];
}
if (typeof options === 'function') {
options = { type: options };
}
if (this.get('noedit')) {
options.noedit = true;
}
if (!options.note && this.get('notes')) {
options.note = this... | Creates a new field at the specified path, with the provided options.
If no options are provides, returns the field at the specified path. | field | javascript | keystonejs/keystone-classic | lib/list/field.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/field.js | MIT |
function getAdminURL (item) {
return '/' + this.keystone.get('admin path') + '/' + this.path + (item ? '/' + item.id : '');
} | Gets the Admin URL to view the list (or an item if provided)
Example:
var listURL = list.getAdminURL()
var itemURL = list.getAdminURL(item)
@param {Object} item | getAdminURL | javascript | keystonejs/keystone-classic | lib/list/getAdminURL.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getAdminURL.js | MIT |
function transformFieldValue (field, item, options) {
var transform = typeof field.options.toCSV === 'string'
? listToArray(field.options.toCSV)
: field.options.toCSV;
if (typeof transform === 'function') {
return transform.call(item, field, options);
}
if (Array.isArray(transform)) {
var value = item.get(f... | Applies option field transforms to get the CSV value for a field | transformFieldValue | javascript | keystonejs/keystone-classic | lib/list/getCSVData.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getCSVData.js | MIT |
function getCSVData (item, options) {
if (!options) {
options = {};
}
options.fields;
if (options.fields === undefined) {
options.fields = Object.keys(this.options.fields);
}
var data = {
id: String(item.id),
};
if (this.autokey) {
data[this.autokey.path] = item.get(this.autokey.path);
}
if (options.f... | Gets the data from an Item ready to be serialised to CSV for download | getCSVData | javascript | keystonejs/keystone-classic | lib/list/getCSVData.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getCSVData.js | MIT |
function getData (item, fields, expandRelationshipFields) {
var data = {
id: item.id,
name: this.getDocumentName(item),
};
if (this.autokey) {
data[this.autokey.path] = item.get(this.autokey.path);
}
if (this.options.sortable) {
data.sortOrder = item.sortOrder;
}
if (fields === undefined) {
fields = Ob... | Gets the data from an Item ready to be serialised for client-side use, as
used by the React components and the Admin API | getData | javascript | keystonejs/keystone-classic | lib/list/getData.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getData.js | MIT |
function getDocumentName (doc, escape) {
// console.log('getting document name for ' + doc.id, 'nameField: ' + this.nameField, 'namePath: ' + this.namePath);
// console.log('raw name value: ', doc.get(this.namePath));
// if (this.nameField) console.log('formatted name value: ', this.nameField.format(doc));
var name... | Gets the name of the provided document from the correct path
Example:
var name = list.getDocumentName(item)
@param {Object} item
@param {Boolean} escape - causes HTML entities to be encoded | getDocumentName | javascript | keystonejs/keystone-classic | lib/list/getDocumentName.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getDocumentName.js | MIT |
function getOptions () {
var ops = {
autocreate: this.options.autocreate,
autokey: this.autokey,
defaultColumns: this.options.defaultColumns,
defaultSort: this.options.defaultSort,
fields: {},
hidden: this.options.hidden,
initialFields: _.map(this.initialFields, 'path'),
key: this.key,
label: this.la... | Gets the options for the List, as used by the React components | getOptions | javascript | keystonejs/keystone-classic | lib/list/getOptions.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getOptions.js | MIT |
function getPages (options, maxPages) {
var surround = Math.floor(maxPages / 2);
var firstPage = maxPages ? Math.max(1, options.currentPage - surround) : 1;
var padRight = Math.max(((options.currentPage - surround) - 1) * -1, 0);
var lastPage = maxPages ? Math.min(options.totalPages, options.currentPage + surround ... | Generate page array for pagination
@param {Number} the maximum number pages to display in the pagination
@param {Object} page options | getPages | javascript | keystonejs/keystone-classic | lib/list/getPages.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getPages.js | MIT |
function getSearchFilters (search, add) {
var filters = {};
var list = this;
search = String(search || '').trim();
if (search.length) {
// Use the text index the behaviour is enabled by the list schema
// Usually, when searchUsesTextIndex is true, list.register() will maintain an index using ensureTextIndex()... | Gets filters for a Mongoose query that will search for the provided string,
based on the searchFields List option.
Also accepts a filters object from `processFilters()`, any of which may
override the search string.
NOTE: This function is deprecated in favor of List.prototype.addSearchToQuery
and will be removed in a ... | getSearchFilters | javascript | keystonejs/keystone-classic | lib/list/getSearchFilters.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getSearchFilters.js | MIT |
function getUniqueValue (path, generator, limit, callback) {
var model = this.model;
var count = 0;
var value;
if (typeof limit === 'function') {
callback = limit;
limit = 10;
}
if (Array.isArray(generator)) {
var fn = generator[0];
var args = generator.slice(1);
generator = function () {
return fn.a... | Gets a unique value from a generator method by checking for documents with the same value.
To avoid infinite loops when a unique value cannot be found, it will bail and pass back an
undefined value after 10 attemptes.
WARNING: Because there will always be a small amount of time between checking for an
existing value ... | getUniqueValue | javascript | keystonejs/keystone-classic | lib/list/getUniqueValue.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getUniqueValue.js | MIT |
check = function () {
if (count++ > 10) {
return callback(undefined, undefined);
}
value = generator();
model.count().where(path, value).exec(function (err, matches) {
if (err) return callback(err);
if (matches) return check();
callback(undefined, value);
});
} | Gets a unique value from a generator method by checking for documents with the same value.
To avoid infinite loops when a unique value cannot be found, it will bail and pass back an
undefined value after 10 attemptes.
WARNING: Because there will always be a small amount of time between checking for an
existing value ... | check | javascript | keystonejs/keystone-classic | lib/list/getUniqueValue.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/getUniqueValue.js | MIT |
function isReserved (path) {
return reservedPaths.indexOf(path) >= 0;
} | Check whether or not a `path` is a reserved path. This restricts the use
of `Object.prototype` method keys as well as internal mongo paths. | isReserved | javascript | keystonejs/keystone-classic | lib/list/isReserved.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/isReserved.js | MIT |
function map (field, path) {
if (path) {
this.mappings[field] = path;
}
return this.mappings[field];
} | Maps a built-in field (e.g. name) to a specific path | map | javascript | keystonejs/keystone-classic | lib/list/map.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/map.js | MIT |
function paginate (options, callback) {
var list = this;
var model = this.model;
options = options || {};
var query = model.find(options.filters, options.optionalExpression);
var countQuery = model.find(options.filters);
query._original_exec = query.exec;
query._original_sort = query.sort;
query._original_se... | Gets a special Query object that will paginate documents in the list
Example:
list.paginate({
page: 1,
perPage: 100,
maxPages: 10
}).exec(function(err, results) {
// do something
});
@param {Object} options
@param {Function} callback (optional) | paginate | javascript | keystonejs/keystone-classic | lib/list/paginate.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/paginate.js | MIT |
function processFilters (q) {
var list = this;
var filters = {};
queryfilterlib.QueryFilters.create(q).getFilters().forEach(function (filter) {
filter.path = filter.key; // alias for b/c
filter.field = list.fields[filter.key];
filters[filter.path] = filter;
});
return filters;
} | Processes a filter string into a filters object
NOTE: This function is deprecated in favor of List.prototype.addFiltersToQuery
and will be removed in a later version.
@param {String} filters | processFilters | javascript | keystonejs/keystone-classic | lib/list/processFilters.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/processFilters.js | MIT |
function register () {
var keystone = this.keystone;
var list = this;
/* Handle deprecated options */
if (this.schema.methods.toCSV) {
console.warn(this.key + ' Warning: List.schema.methods.toCSV support has been removed from KeystoneJS.\nPlease use getCSVData instead (see the 0.3 -> 4.0 Upgrade Guide)\n');
}
/... | Registers the Schema with Mongoose, and the List with Keystone
Also adds default fields and virtuals to the schema for the list | register | javascript | keystonejs/keystone-classic | lib/list/register.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/register.js | MIT |
function relationship (def) {
var keystone = this.keystone;
if (arguments.length > 1) {
for (var i = 0; i < arguments.length; i++) {
this.relationship(arguments[i]);
}
return this;
}
if (typeof def === 'string') {
def = { ref: def };
}
if (!def.ref) {
throw new Error('List Relationships must be speci... | Registers relationships to this list defined on others | relationship | javascript | keystonejs/keystone-classic | lib/list/relationship.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/relationship.js | MIT |
function selectColumns (q, cols) {
// Populate relationship columns
var select = [];
var populate = {};
var path;
cols.forEach(function (col) {
select.push(col.path);
if (col.populate) {
if (!populate[col.populate.path]) {
populate[col.populate.path] = [];
}
populate[col.populate.path].push(col.po... | Specified select and populate options for a query based the provided columns.
@param {Query} query
@param {Array} columns | selectColumns | javascript | keystonejs/keystone-classic | lib/list/selectColumns.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/selectColumns.js | MIT |
function set (key, value) {
if (arguments.length === 1) {
return this.options[key];
}
this.options[key] = value;
return value;
} | Gets and Sets list options. Aliased as .get()
Example:
list.set('test') // returns the 'test' value
list.set('test', value) // sets the 'test' option to `value` | set | javascript | keystonejs/keystone-classic | lib/list/set.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/set.js | MIT |
function underscoreMethod (path, fn) {
var target = this.underscoreMethods;
path = path.split('.');
var last = path.pop();
path.forEach(function (part) {
if (!target[part]) target[part] = {};
target = target[part];
});
target[last] = fn;
return this;
} | Adds a method to the underscoreMethods collection on the list, which is then
added to the schema before the list is registered with mongoose. | underscoreMethod | javascript | keystonejs/keystone-classic | lib/list/underscoreMethod.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/list/underscoreMethod.js | MIT |
function Storage (options) {
// we're going to mutate options so get a clean copy of it
options = assign({}, options);
var AdapterType = options.adapter;
delete options.adapter;
if (typeof AdapterType !== 'function') {
throw new Error('Invalid Storage Adapter\n'
+ 'The storage adapter specified is not a fun... | # Storage Prototype
Creates a new Keystone Storage instance, and validates and initialises the
specified adapter. Storage schema is configured from the adapter or default. | Storage | javascript | keystonejs/keystone-classic | lib/storage/index.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/storage/index.js | MIT |
function getSize (file, callback) {
if (file.size) return callback(null, file.size);
fs.stat(file.path, function (err, stats) {
if (!stats.isFile()) {
return callback(Error(file.path + ' is not a file'));
}
callback(err, stats ? stats.size : null);
});
} | # Storage Prototype
Creates a new Keystone Storage instance, and validates and initialises the
specified adapter. Storage schema is configured from the adapter or default. | getSize | javascript | keystonejs/keystone-classic | lib/storage/index.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/storage/index.js | MIT |
function normalizeFile (file, schema, callback) {
// Detect required information if it wasn't provided by inspecting the
// file stored at file.path
if (schema.mimetype && !file.mimetype) file.mimetype = mime(file.path);
if (!file.originalname) {
file.originalname = file.name
|| (file.path) ? path.parse(file.... | # Storage Prototype
Creates a new Keystone Storage instance, and validates and initialises the
specified adapter. Storage schema is configured from the adapter or default. | normalizeFile | javascript | keystonejs/keystone-classic | lib/storage/index.js | https://github.com/keystonejs/keystone-classic/blob/master/lib/storage/index.js | MIT |
function ready (err) {
callback(err, message);
} | Configures and starts express server in SSL.
Events are fired during initialisation to allow customisation, including:
- onHttpsServerCreated
consumed by lib/core/start.js
@api private | ready | javascript | keystonejs/keystone-classic | server/startSecureServer.js | https://github.com/keystonejs/keystone-classic/blob/master/server/startSecureServer.js | MIT |
function kebabify (string) {
return string
.split('/')
.map(s => kebabCase(s))
.join('/');
} | Implement Gatsby's Node APIs in this file.
See: https://www.gatsbyjs.org/docs/node-apis/ | kebabify | javascript | keystonejs/keystone-classic | website/gatsby-node.js | https://github.com/keystonejs/keystone-classic/blob/master/website/gatsby-node.js | MIT |
set(key, value) {
throw new Error('Set is not overridden!');
} | @param {!string} key
@param {!string} value
@return {!Promise} | set | javascript | yujiosaka/headless-chrome-crawler | cache/base.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/base.js | MIT |
enqueue(key, value, priority) {
throw new Error('Enqueue is not overridden!');
} | @param {!string} key
@param {!string} value
@param {!number=} priority
@return {!Promise} | enqueue | javascript | yujiosaka/headless-chrome-crawler | cache/base.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/base.js | MIT |
size(key) {
throw new Error('Size is not overridden!');
} | @param {!string} key
@return {!Promise<!number>} | size | javascript | yujiosaka/headless-chrome-crawler | cache/base.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/base.js | MIT |
get(key) {
return new Promise((resolve, reject) => {
this._client.get(key, (error, json) => {
if (error) {
reject(error);
return;
}
try {
const value = JSON.parse(json || null);
resolve(value);
} catch (_error) {
reject(_error);... | @param {!string} key
@return {!Promise}
@override | get | javascript | yujiosaka/headless-chrome-crawler | cache/redis.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js | MIT |
set(key, value) {
return new Promise((resolve, reject) => {
let json;
try {
json = JSON.stringify(value);
} catch (error) {
reject(error);
return;
}
this._client.set(key, json, error => {
if (error) {
reject(error);
return;
}
... | @param {!string} key
@param {!string} value
@return {!Promise}
@override | set | javascript | yujiosaka/headless-chrome-crawler | cache/redis.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js | MIT |
enqueue(key, value, priority = 1) {
return new Promise((resolve, reject) => {
let json;
try {
json = JSON.stringify(value);
} catch (error) {
reject(error);
return;
}
this._client.zadd(key, priority, json, error => {
if (error) {
reject(error);... | @param {!string} key
@param {!string} value
@param {!number=} priority
@return {!Promise}
@override | enqueue | javascript | yujiosaka/headless-chrome-crawler | cache/redis.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js | MIT |
dequeue(key) {
return new Promise((resolve, reject) => {
this._client.eval(DEQUEUE_SCRIPT, 1, key, (error, json) => {
if (error) {
reject(error);
return;
}
try {
const value = JSON.parse(json || null);
resolve(value);
} catch (_error) {
... | @param {!string} key
@return {!Promise}
@override | dequeue | javascript | yujiosaka/headless-chrome-crawler | cache/redis.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js | MIT |
size(key) {
return new Promise((resolve, reject) => {
this._client.zcount(key, '-inf', 'inf', (error, size) => {
if (error) {
reject(error);
return;
}
resolve(size || 0);
});
});
} | @param {!string} key
@return {!Promise<!number>}
@override | size | javascript | yujiosaka/headless-chrome-crawler | cache/redis.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js | MIT |
remove(key) {
return new Promise((resolve, reject) => {
this._client.del(key, error => {
if (error) {
reject(error);
return;
}
resolve();
});
});
} | @param {!string} key
@return {!Promise}
@override | remove | javascript | yujiosaka/headless-chrome-crawler | cache/redis.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js | MIT |
get(key) {
return Promise.resolve(this._storage.get(key) || null);
} | @param {!string} key
@return {!Promise}
@override | get | javascript | yujiosaka/headless-chrome-crawler | cache/session.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/session.js | MIT |
set(key, value) {
this._storage.set(key, value);
return Promise.resolve();
} | @param {!string} key
@param {!string} value
@return {!Promise}
@override | set | javascript | yujiosaka/headless-chrome-crawler | cache/session.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/session.js | MIT |
enqueue(key, value, priority) {
const queue = this._storage.get(key) || [];
const item = { value, priority };
if (queue.length && queue[queue.length - 1].priority >= priority) {
queue.push(item);
this._storage.set(key, queue);
return Promise.resolve();
}
const index = lowerBound(qu... | @param {!string} key
@param {!string} value
@param {!number=} priority
@return {!Promise}
@override | enqueue | javascript | yujiosaka/headless-chrome-crawler | cache/session.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/session.js | MIT |
dequeue(key) {
const queue = this._storage.get(key) || [];
this._storage.set(key, queue);
const item = queue.shift();
if (!item) return Promise.resolve(null);
return Promise.resolve(item.value);
} | @param {!string} key
@return {!Promise}
@override | dequeue | javascript | yujiosaka/headless-chrome-crawler | cache/session.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/session.js | MIT |
size(key) {
const queue = this._storage.get(key);
if (!queue) return Promise.resolve(0);
return Promise.resolve(queue.length);
} | @param {!string} key
@return {!Promise<!number>}
@override | size | javascript | yujiosaka/headless-chrome-crawler | cache/session.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/session.js | MIT |
remove(key) {
this._storage.delete(key);
return Promise.resolve();
} | @param {!string} key
@return {!Promise}
@override | remove | javascript | yujiosaka/headless-chrome-crawler | cache/session.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/session.js | MIT |
emitAsync(event, ...args) {
const promises = [];
this.listeners(event).forEach(listener => {
promises.push(listener(...args));
});
return Promise.all(promises);
} | @param {!string} event
@param {...*} args
@return {!Promise} | emitAsync | javascript | yujiosaka/headless-chrome-crawler | lib/async-events.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/async-events.js | MIT |
constructor(page, options, depth, previousUrl) {
this._page = page;
this._options = options;
this._depth = depth;
this._previousUrl = previousUrl;
} | @param {!Puppeteer.Page} page
@param {!Object} options
@param {!number} depth
@param {string} previousUrl | constructor | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
async _handleDialog(dialog) {
debugDialog(`${dialog.type()} ${dialog.message()} at ${this._options.url}`);
await dialog.dismiss();
} | @param {!Puppeteer.Dialog} dialog
@return {!Promise}
@private | _handleDialog | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
async _collectLinks(baseUrl) {
const links = [];
await this._page.exposeFunction('pushToLinks', link => {
const _link = resolveUrl(link, baseUrl);
if (_link) links.push(_link);
});
await this._page.evaluate(() => {
function findLinks(document) {
document.querySelectorAll('a[hre... | @param {!string} baseUrl
@return {!Promise<!Array<!string>>}
@private | _collectLinks | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
function findLinks(document) {
document.querySelectorAll('a[href]')
.forEach(link => {
// @ts-ignore
window.pushToLinks(link.href);
});
document.querySelectorAll('iframe,frame')
.forEach(frame => {
try {
findLinks(frame.cont... | @param {!string} baseUrl
@return {!Promise<!Array<!string>>}
@private | findLinks | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
_reduceRequest(request) {
return reduce(REQUEST_FIELDS, (memo, field) => {
memo[field] = request[field]();
return memo;
}, {});
} | @param {!Puppeteer.Request} request
@return {!Object}
@private | _reduceRequest | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
_reduceResponse(response) {
return reduce(RESPONSE_FIELDS, (memo, field) => {
memo[field] = response[field]();
return memo;
}, {});
} | @param {!Puppeteer.Response} response
@return {!Object}
@private | _reduceResponse | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
_getRedirectChain(response) {
return map(response.request().redirectChain(), this._reduceRequest);
} | @param {!Puppeteer.Response} response
@return {!Array<!Object>}
@private | _getRedirectChain | javascript | yujiosaka/headless-chrome-crawler | lib/crawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/crawler.js | MIT |
static async connect(options) {
const browser = await Puppeteer.connect(pick(options, CONNECT_OPTIONS));
const crawler = new HCCrawler(browser, omit(options, CONNECT_OPTIONS));
await crawler.init();
return crawler;
} | @param {!Object=} options
@return {!Promise<!HCCrawler>} | connect | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
static async launch(options) {
const browser = await Puppeteer.launch(pick(options, LAUNCH_OPTIONS));
const crawler = new HCCrawler(browser, omit(options, LAUNCH_OPTIONS));
await crawler.init();
return crawler;
} | @param {!Object=} options
@return {!Promise<!HCCrawler>} | launch | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
constructor(browser, options) {
super();
this._browser = browser;
this._options = extend({
maxDepth: 1,
maxConcurrency: 10,
maxRequest: 0,
priority: 0,
delay: 0,
retryCount: 3,
retryDelay: 10000,
timeout: 30000,
jQuery: true,
browserCache: true,
... | @param {!Puppeteer.Browser} browser
@param {!Object} options | constructor | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async queue(options) {
await Promise.all(map(isArray(options) ? options : [options], async _options => {
const queueOptions = isString(_options) ? { url: _options } : _options;
each(CONSTRUCTOR_OPTIONS, option => {
if (queueOptions && queueOptions[option]) throw new Error(`Overriding ${option} i... | @param {?Object|?Array<!string>|?string} options
@return {!Promise} | queue | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _push(options, depth, previousUrl) {
let { priority } = options;
if (!priority && options.depthPriority) priority = depth;
await this._queue.push(options, depth, previousUrl, priority);
} | @param {!Object} options
@param {!number} depth
@param {string} previousUrl
@return {!Promise} | _push | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _startRequest(options, depth, previousUrl) {
const skip = await this._skipRequest(options);
if (skip) {
this.emit(HCCrawler.Events.RequestSkipped, options);
await this._markRequested(options);
return;
}
const allowed = await this._checkAllowedRobots(options, depth, previousUrl);
... | @param {!Object} options
@param {!number} depth
@param {string} previousUrl
@return {!Promise}
@private | _startRequest | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _skipRequest(options) {
const allowedDomain = this._checkAllowedDomains(options);
if (!allowedDomain) return true;
const requested = await this._checkRequested(options);
if (requested) return true;
const shouldRequest = await this._shouldRequest(options);
if (!shouldRequest) return true;
... | @param {!Object} options
@return {!Promise<!boolean>}
@private | _skipRequest | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _request(options, depth, previousUrl, retryCount = 0) {
this.emit(HCCrawler.Events.RequestStarted, options);
const crawler = await this._newCrawler(options, depth, previousUrl);
try {
const res = await this._crawl(crawler);
await crawler.close();
this.emit(HCCrawler.Events.RequestFin... | @param {!Object} options
@param {!number} depth
@param {string} previousUrl
@param {!number=} retryCount
@return {!Promise<!Array<!string>>}
@private | _request | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _checkAllowedRobots(options, depth, previousUrl) {
if (!options.obeyRobotsTxt) return true;
const robot = await this._getRobot(options, depth, previousUrl);
const userAgent = await this._getUserAgent(options);
return robot.isAllowed(options.url, userAgent);
} | @param {!Object} options
@param {!number} depth
@param {string} previousUrl
@return {!Promise<!boolean>}
@private | _checkAllowedRobots | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _followSitemap(options, depth, previousUrl) {
if (!options.followSitemapXml) return;
const robot = await this._getRobot(options, depth, previousUrl);
const sitemapUrls = robot.getSitemaps();
await Promise.resolve(map(sitemapUrls, async sitemapUrl => {
const sitemapXml = await this._getSitema... | @param {!Object} options
@param {!number} depth
@param {string} previousUrl
@return {!Promise}
@private | _followSitemap | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _getSitemapXml(sitemapUrl, options, depth, previousUrl) {
let sitemapXml = await this._cache.get(sitemapUrl);
if (!sitemapXml) {
try {
sitemapXml = await rp(sitemapUrl);
} catch (error) {
extend(error, { options, depth, previousUrl });
this.emit(HCCrawler.Events.Sitemap... | @param {!string} sitemapUrl
@param {!Object} options
@param {!number} depth
@param {string} previousUrl
@return {!Promise<!string>} | _getSitemapXml | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _getRobot(options, depth, previousUrl) {
const robotsUrl = getRobotsUrl(options.url);
let robotsTxt = await this._cache.get(robotsUrl);
if (!robotsTxt) {
try {
robotsTxt = await rp(robotsUrl);
} catch (error) {
extend(error, { options, depth, previousUrl });
this.em... | @param {!Object} options
@param {!number} depth
@param {string} previousUrl
@return {!Promise}
@private | _getRobot | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _getUserAgent(options) {
if (options.userAgent) return options.userAgent;
if (devices[options.device]) return devices[options.device].userAgent;
return this.userAgent();
} | @param {!Object} options
@return {!Promise<!string>}
@private | _getUserAgent | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
_checkAllowedDomains(options) {
const { hostname } = parse(options.url);
if (options.deniedDomains && checkDomainMatch(options.deniedDomains, hostname)) return false;
if (options.allowedDomains && !checkDomainMatch(options.allowedDomains, hostname)) return false;
return true;
} | @param {!Object} options
@return {!boolean}
@private | _checkAllowedDomains | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _checkRequested(options) {
if (!options.skipDuplicates) return false;
const key = generateKey(options);
const value = await this._cache.get(key);
return !!value;
} | @param {!Object} options
@return {!Promise<!boolean>}
@private | _checkRequested | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _checkRequestedRedirect(options, response) {
if (!options.skipRequestedRedirect) return false;
const requested = await this._checkRequested(extend({}, options, { url: response.url }));
return requested;
} | @param {!Object} options
@param {!Object} response
@return {!Promise<!boolean>}
@private | _checkRequestedRedirect | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _markRequested(options) {
if (!options.skipDuplicates) return;
const key = generateKey(options);
await this._cache.set(key, '1');
} | @param {!Object} options
@return {!Promise}
@private | _markRequested | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _markRequestedRedirects(options, redirectChain, response) {
if (!options.skipRequestedRedirect) return;
await Promise.all(map(redirectChain, async request => {
await this._markRequested(extend({}, options, { url: request.url }));
}));
await this._markRequested(extend({}, options, { url: resp... | @param {!Object} options
@param {!Array<!Object>} redirectChain
@param {!Object} response
@return {!Promise}
@private | _markRequestedRedirects | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _shouldRequest(options) {
if (!this._preRequest) return true;
return this._preRequest(options);
} | @param {!Object} options
@return {!Promise<?boolean>}
@private | _shouldRequest | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _success(result) {
if (!this._onSuccess) return;
await this._onSuccess(result);
} | @param {!Object} result
@return {!Promise}
@private | _success | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _error(error) {
if (!this._onError) return;
await this._onError(error);
} | @param {!Error} error
@return {!Promise}
@private | _error | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _newCrawler(options, depth, previousUrl) {
const page = await this._browser.newPage();
return new Crawler(page, options, depth, previousUrl);
} | @param {!Object} options
@return {!Promise<!Crawler>}
@param {!number} depth
@param {string} previousUrl
@private | _newCrawler | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _crawl(crawler) {
if (!this._customCrawl) return crawler.crawl();
const crawl = () => crawler.crawl.call(crawler);
return this._customCrawl(crawler.page(), crawl);
} | @param {!Crawler} crawler
@return {!Promise<!Object>} | _crawl | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
async _followLinks(urls, options, depth) {
if (depth >= options.maxDepth) {
this.emit(HCCrawler.Events.MaxDepthReached);
return;
}
await Promise.all(map(urls, async url => {
const _options = extend({}, options, { url });
const skip = await this._skipRequest(_options);
if (skip)... | @param {!Array<!string>} urls
@param {!Object} options
@param {!number} depth
@return {!Promise}
@private | _followLinks | javascript | yujiosaka/headless-chrome-crawler | lib/hccrawler.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/hccrawler.js | MIT |
static jsonStableReplacer(key, val) {
if (!isPlainObject(val)) return val;
return Object.keys(val).sort().reduce((obj, _key) => {
obj[_key] = val[_key];
return obj;
}, {});
} | @param {!string} key
@param {?*} val
@return {!Object} | jsonStableReplacer | javascript | yujiosaka/headless-chrome-crawler | lib/helper.js | https://github.com/yujiosaka/headless-chrome-crawler/blob/master/lib/helper.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.