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
params(path, captures, params = {}) { for (let len = captures.length, i = 0; i < len; i++) { if (this.paramNames[i]) { const c = captures[i]; if (c && c.length > 0) params[this.paramNames[i].name] = c ? safeDecodeURIComponent(c) : c; } } return params; }
Returns map of URL parameters for given `path` and `paramNames`. @param {String} path @param {Array.<String>} captures @param {Object=} params @returns {Object} @private
params
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
captures(path) { return this.opts.ignoreCaptures ? [] : path.match(this.regexp).slice(1); }
Returns array of regexp url path captures. @param {String} path @returns {Array.<String>} @private
captures
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
url(params, options) { let args = params; const url = this.path.replace(/\(\.\*\)/g, ''); if (typeof params !== 'object') { args = Array.prototype.slice.call(arguments); if (typeof args[args.length - 1] === 'object') { options = args[args.length - 1]; args = args.slice(0, -1); ...
Generate URL for route using given `params`. @example ```javascript const route = new Layer('/users/:id', ['GET'], fn); route.url({ id: 123 }); // => "/users/123" ``` @param {Object} params url parameters @returns {String} @private
url
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
param(param, fn) { const { stack } = this; const params = this.paramNames; const middleware = function (ctx, next) { return fn.call(this, ctx.params[param], ctx, next); }; middleware.param = param; const names = params.map(function (p) { return p.name; }); const x = names....
Run validations on route named parameters. @example ```javascript router .param('user', function (id, ctx, next) { ctx.user = users[id]; if (!ctx.user) return ctx.status = 404; next(); }) .get('/users/:user', function (ctx, next) { ctx.body = ctx.user; }); ``` @param {String} param @param {Fu...
param
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
middleware = function (ctx, next) { return fn.call(this, ctx.params[param], ctx, next); }
Run validations on route named parameters. @example ```javascript router .param('user', function (id, ctx, next) { ctx.user = users[id]; if (!ctx.user) return ctx.status = 404; next(); }) .get('/users/:user', function (ctx, next) { ctx.body = ctx.user; }); ``` @param {String} param @param {Fu...
middleware
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
middleware = function (ctx, next) { return fn.call(this, ctx.params[param], ctx, next); }
Run validations on route named parameters. @example ```javascript router .param('user', function (id, ctx, next) { ctx.user = users[id]; if (!ctx.user) return ctx.status = 404; next(); }) .get('/users/:user', function (ctx, next) { ctx.body = ctx.user; }); ``` @param {String} param @param {Fu...
middleware
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
setPrefix(prefix) { if (this.path) { this.path = this.path !== '/' || this.opts.strict === true ? `${prefix}${this.path}` : prefix; this.paramNames = []; this.regexp = pathToRegexp(this.path, this.paramNames, this.opts); } return this; }
Prefix route path. @param {String} prefix @returns {Layer} @private
setPrefix
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
function safeDecodeURIComponent(text) { try { // TODO: take a look on `safeDecodeURIComponent` if we use it only with route params let's remove the `replace` method otherwise make it flexible. // @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#decoding...
Safe decodeURIComponent, won't throw any error. If `decodeURIComponent` error happen, just return the original value. @param {String} text @returns {String} URL decode original string. @private
safeDecodeURIComponent
javascript
koajs/router
lib/layer.js
https://github.com/koajs/router/blob/master/lib/layer.js
MIT
constructor(opts = {}) { if (!(this instanceof Router)) return new Router(opts); // eslint-disable-line no-constructor-return this.opts = opts; this.methods = this.opts.methods || [ 'HEAD', 'OPTIONS', 'GET', 'PUT', 'PATCH', 'POST', 'DELETE' ]; this.exclusiv...
Create a new router. @example Basic usage: ```javascript const Koa = require('koa'); const Router = require('@koa/router'); const app = new Koa(); const router = new Router(); router.get('/', (ctx, next) => { // ctx.router available }); app .use(router.routes()) .use(router.allowedMethods()); ``` @alias mo...
constructor
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
static url(path, ...args) { return Layer.prototype.url.apply({ path }, args); }
Generate URL from url pattern and given `params`. @example ```javascript const url = Router.url('/users/:id', {id: 1}); // => "/users/1" ``` @param {String} path url pattern @param {Object} params url parameters @returns {String}
url
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
use(...middleware) { const router = this; let path; // support array of paths if (Array.isArray(middleware[0]) && typeof middleware[0][0] === 'string') { const arrPaths = middleware[0]; for (const p of arrPaths) { router.use.apply(router, [p, ...middleware.slice(1)]); } ...
Use given middleware. Middleware run in the order they are defined by `.use()`. They are invoked sequentially, requests start at the first middleware and work their way "down" the middleware stack. @example ```javascript // session middleware will run before authorize router .use(session()) .use(authorize()); /...
use
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
prefix(prefix) { prefix = prefix.replace(/\/$/, ''); this.opts.prefix = prefix; for (let i = 0; i < this.stack.length; i++) { const route = this.stack[i]; route.setPrefix(prefix); } return this; }
Set the path prefix for a Router instance that was already initialized. @example ```javascript router.prefix('/things/:thing_id') ``` @param {String} prefix @returns {Router}
prefix
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
middleware() { const router = this; const dispatch = (ctx, next) => { debug('%s %s', ctx.method, ctx.path); const hostMatched = router.matchHost(ctx.host); if (!hostMatched) { return next(); } const path = router.opts.routerPath || ctx.newRouterPath || ...
Returns router middleware which dispatches a route matching the request. @returns {Function}
middleware
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
dispatch = (ctx, next) => { debug('%s %s', ctx.method, ctx.path); const hostMatched = router.matchHost(ctx.host); if (!hostMatched) { return next(); } const path = router.opts.routerPath || ctx.newRouterPath || ctx.path || ctx.routerPath; co...
Returns router middleware which dispatches a route matching the request. @returns {Function}
dispatch
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
dispatch = (ctx, next) => { debug('%s %s', ctx.method, ctx.path); const hostMatched = router.matchHost(ctx.host); if (!hostMatched) { return next(); } const path = router.opts.routerPath || ctx.newRouterPath || ctx.path || ctx.routerPath; co...
Returns router middleware which dispatches a route matching the request. @returns {Function}
dispatch
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
routes() { return this.middleware(); }
Returns router middleware which dispatches a route matching the request. @returns {Function}
routes
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
allowedMethods(options = {}) { const implemented = this.methods; return (ctx, next) => { return next().then(() => { const allowed = {}; if (ctx.matched && (!ctx.status || ctx.status === 404)) { for (let i = 0; i < ctx.matched.length; i++) { const route = ctx.matched...
Returns separate middleware for responding to `OPTIONS` requests with an `Allow` header containing the allowed methods, as well as responding with `405 Method Not Allowed` and `501 Not Implemented` as appropriate. @example ```javascript const Koa = require('koa'); const Router = require('@koa/router'); const app = n...
allowedMethods
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
all(name, path, middleware) { if (typeof path === 'string') { middleware = Array.prototype.slice.call(arguments, 2); } else { middleware = Array.prototype.slice.call(arguments, 1); path = name; name = null; } // Sanity check to ensure we have a viable path candidate (eg: string|...
Register route with all methods. @param {String} name Optional. @param {String} path @param {Function=} middleware You may also pass multiple middleware. @param {Function} callback @returns {Router}
all
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
redirect(source, destination, code) { // lookup source route by name if (typeof source === 'symbol' || source[0] !== '/') { source = this.url(source); if (source instanceof Error) throw source; } // lookup destination route by name if ( typeof destination === 'symbol' || (de...
Redirect `source` to `destination` URL with optional 30x status `code`. Both `source` and `destination` can be route names. ```javascript router.redirect('/login', 'sign-in'); ``` This is equivalent to: ```javascript router.all('/login', ctx => { ctx.redirect('/sign-in'); ctx.status = 301; }); ``` @param {Stri...
redirect
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
register(path, methods, middleware, opts = {}) { const router = this; const { stack } = this; // support array of paths if (Array.isArray(path)) { for (const curPath of path) { router.register.call(router, curPath, methods, middleware, opts); } return this; } // crea...
Create and register a route. @param {String} path Path string. @param {Array.<String>} methods Array of HTTP verbs. @param {Function} middleware Multiple middleware also accepted. @returns {Layer} @private
register
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
route(name) { const routes = this.stack; for (let len = routes.length, i = 0; i < len; i++) { if (routes[i].name && routes[i].name === name) return routes[i]; } return false; }
Lookup route with given `name`. @param {String} name @returns {Layer|false}
route
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
match(path, method) { const layers = this.stack; let layer; const matched = { path: [], pathAndMethod: [], route: false }; for (let len = layers.length, i = 0; i < len; i++) { layer = layers[i]; debug('test %s %s', layer.path, layer.regexp); // eslint-disable-n...
Match given `path` and return corresponding routes. @param {String} path @param {String} method @returns {Object.<path, pathAndMethod>} returns layers that matched path and path and method. @private
match
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
matchHost(input) { const { host } = this; if (!host) { return true; } if (!input) { return false; } if (typeof host === 'string') { return input === host; } if (typeof host === 'object' && host instanceof RegExp) { return host.test(input); } }
Match given `input` to allowed host @param {String} input @returns {boolean}
matchHost
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
param(param, middleware) { this.params[param] = middleware; for (let i = 0; i < this.stack.length; i++) { const route = this.stack[i]; route.param(param, middleware); } return this; }
Run middleware for named route parameters. Useful for auto-loading or validation. @example ```javascript router .param('user', (id, ctx, next) => { ctx.user = users[id]; if (!ctx.user) return ctx.status = 404; return next(); }) .get('/users/:user', ctx => { ctx.body = ctx.user; }) .get('/use...
param
javascript
koajs/router
lib/router.js
https://github.com/koajs/router/blob/master/lib/router.js
MIT
function loadData(locations, response, callback) { if (locations.length === 0) callback(null, response); else $.get(locations.shift()) .fail(function(e) { callback(e, null); }) .done(function (data) { if (response.length > 0) response += '\n\n'; respons...
File fetcher function. Fetches a given `url` via AJAX. See [Runner#run()] for a description of fetcher functions.
loadData
javascript
localForage/localForage
docs/scripts/flatdoc.js
https://github.com/localForage/localForage/blob/master/docs/scripts/flatdoc.js
Apache-2.0
function mkdir_p(level) { cache.length = level + 1; var obj = cache[level]; if (!obj) { var parent = (level > 1) ? mkdir_p(level-1) : root; obj = { items: [], level: level }; cache = cache.concat([obj, obj]); parent.items.push(obj); } return obj; }
Returns menu data for a given HTML. menu = Flatdoc.transformer.getMenu($content); menu == { level: 0, items: [{ section: "Getting started", level: 1, items: [...]}, ...]}
mkdir_p
javascript
localForage/localForage
docs/scripts/flatdoc.js
https://github.com/localForage/localForage/blob/master/docs/scripts/flatdoc.js
Apache-2.0
function getTextNodesIn(el) { var exclude = 'iframe,pre,code'; return $(el).find(':not('+exclude+')').andSelf().contents().filter(function() { return this.nodeType == 3 && $(this).closest(exclude).length === 0; }); }
Fetches a given element from the DOM. Returns a jQuery object. @api private
getTextNodesIn
javascript
localForage/localForage
docs/scripts/flatdoc.js
https://github.com/localForage/localForage/blob/master/docs/scripts/flatdoc.js
Apache-2.0
function quotify(a) { a = a.replace(/(^|[\-\u2014\s(\["])'/g, "$1\u2018"); // opening singles a = a.replace(/'/g, "\u2019"); // closing singles & apostrophes a = a.replace(/(^|[\-\u2014\/\[(\u2018\s])"/g, "$1\u201c"); // opening doubles a = a.replace(/"/g, "\u201d"); ...
Fetches a given element from the DOM. Returns a jQuery object. @api private
quotify
javascript
localForage/localForage
docs/scripts/flatdoc.js
https://github.com/localForage/localForage/blob/master/docs/scripts/flatdoc.js
Apache-2.0
function each(ary, func) { if (ary) { var i; for (i = 0; i < ary.length; i += 1) { if (ary[i] && func(ary[i], i, ary)) { break; } } } }
Helper function for iterating over an array. If the func returns a true value, it will break out of the loop.
each
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function eachReverse(ary, func) { if (ary) { var i; for (i = ary.length - 1; i > -1; i -= 1) { if (ary[i] && func(ary[i], i, ary)) { break; } } } }
Helper function for iterating over an array backwards. If the func returns a true value, it will break out of the loop.
eachReverse
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function hasProp(obj, prop) { return hasOwn.call(obj, prop); }
Helper function for iterating over an array backwards. If the func returns a true value, it will break out of the loop.
hasProp
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function getOwn(obj, prop) { return hasProp(obj, prop) && obj[prop]; }
Helper function for iterating over an array backwards. If the func returns a true value, it will break out of the loop.
getOwn
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function eachProp(obj, func) { var prop; for (prop in obj) { if (hasProp(obj, prop)) { if (func(obj[prop], prop)) { break; } } } }
Cycles over properties in an object and calls a function for each property value. If the function returns a truthy value, then the iteration is stopped.
eachProp
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function mixin(target, source, force, deepStringMixin) { if (source) { eachProp(source, function (value, prop) { if (force || !hasProp(target, prop)) { if (deepStringMixin && typeof value !== 'string') { if (!target[prop]) { ...
Simple function to mix in properties from source into target, but only if target does not already have a property of the same name.
mixin
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function bind(obj, fn) { return function () { return fn.apply(obj, arguments); }; }
Simple function to mix in properties from source into target, but only if target does not already have a property of the same name.
bind
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function scripts() { return document.getElementsByTagName('script'); }
Simple function to mix in properties from source into target, but only if target does not already have a property of the same name.
scripts
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function getGlobal(value) { if (!value) { return value; } var g = global; each(value.split('.'), function (part) { g = g[part]; }); return g; }
Simple function to mix in properties from source into target, but only if target does not already have a property of the same name.
getGlobal
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function makeError(id, msg, err, requireModules) { var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id); e.requireType = id; e.requireModules = requireModules; if (err) { e.originalError = err; } return e; }
Constructs an error with a pointer to an URL with more information. @param {String} id the error ID that maps to an ID on a web page. @param {String} message human readable error. @param {Error} [err] the original error, if there is one. @returns {Error}
makeError
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function newContext(contextName) { var inCheckLoaded, Module, context, handlers, checkLoadedTimeoutId, config = { //Defaults. Do not set a default for map //config to speed up normalize(), which //will run faster if there is no default. ...
Constructs an error with a pointer to an URL with more information. @param {String} id the error ID that maps to an ID on a web page. @param {String} message human readable error. @param {Error} [err] the original error, if there is one. @returns {Error}
newContext
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function trimDots(ary) { var i, part; for (i = 0; ary[i]; i += 1) { part = ary[i]; if (part === '.') { ary.splice(i, 1); i -= 1; } else if (part === '..') { if (i === 1 && (ary[2] === '..'...
Trims the . and .. from an array of path segments. It will keep a leading path segment if a .. will become the first path segment, to help with module name lookups, which act like paths, but can be remapped. But the end result, all paths that use this function should look normalized. NOTE: this method MODIFIES the inpu...
trimDots
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function normalize(name, baseName, applyMap) { var pkgName, pkgConfig, mapValue, nameParts, i, j, nameSegment, foundMap, foundI, foundStarMap, starI, baseParts = baseName && baseName.split('/'), normalizedBaseParts = baseParts, map = config.map...
Given a relative module name, like ./something, normalize it to a real name that can be mapped to a path. @param {String} name the relative name @param {String} baseName a real name that the name arg is relative to. @param {Boolean} applyMap apply the map config to the value. Should only be done if this normalization i...
normalize
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function removeScript(name) { if (isBrowser) { each(scripts(), function (scriptNode) { if (scriptNode.getAttribute('data-requiremodule') === name && scriptNode.getAttribute('data-requirecontext') === context.contextName) { ...
Given a relative module name, like ./something, normalize it to a real name that can be mapped to a path. @param {String} name the relative name @param {String} baseName a real name that the name arg is relative to. @param {Boolean} applyMap apply the map config to the value. Should only be done if this normalization i...
removeScript
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function hasPathFallback(id) { var pathConfig = getOwn(config.paths, id); if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) { removeScript(id); //Pop off the first array value, since it failed, and //retry pathConfig.s...
Given a relative module name, like ./something, normalize it to a real name that can be mapped to a path. @param {String} name the relative name @param {String} baseName a real name that the name arg is relative to. @param {Boolean} applyMap apply the map config to the value. Should only be done if this normalization i...
hasPathFallback
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function splitPrefix(name) { var prefix, index = name ? name.indexOf('!') : -1; if (index > -1) { prefix = name.substring(0, index); name = name.substring(index + 1, name.length); } return [prefix, name]; }
Given a relative module name, like ./something, normalize it to a real name that can be mapped to a path. @param {String} name the relative name @param {String} baseName a real name that the name arg is relative to. @param {Boolean} applyMap apply the map config to the value. Should only be done if this normalization i...
splitPrefix
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) { var url, pluginModule, suffix, nameParts, prefix = null, parentName = parentModuleMap ? parentModuleMap.name : null, originalName = name, isDefine = true, n...
Creates a module mapping that includes plugin prefix, module name, and path. If parentModuleMap is provided it will also normalize the name via require.normalize() @param {String} name the module name @param {String} [parentModuleMap] parent module map for the module name, used to resolve relative names. @param {Boole...
makeModuleMap
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function getModule(depMap) { var id = depMap.id, mod = getOwn(registry, id); if (!mod) { mod = registry[id] = new context.Module(depMap); } return mod; }
Creates a module mapping that includes plugin prefix, module name, and path. If parentModuleMap is provided it will also normalize the name via require.normalize() @param {String} name the module name @param {String} [parentModuleMap] parent module map for the module name, used to resolve relative names. @param {Boole...
getModule
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function on(depMap, name, fn) { var id = depMap.id, mod = getOwn(registry, id); if (hasProp(defined, id) && (!mod || mod.defineEmitComplete)) { if (name === 'defined') { fn(defined[id]); } } else...
Creates a module mapping that includes plugin prefix, module name, and path. If parentModuleMap is provided it will also normalize the name via require.normalize() @param {String} name the module name @param {String} [parentModuleMap] parent module map for the module name, used to resolve relative names. @param {Boole...
on
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function onError(err, errback) { var ids = err.requireModules, notified = false; if (errback) { errback(err); } else { each(ids, function (id) { var mod = getOwn(registry, id); if (mod) { ...
Creates a module mapping that includes plugin prefix, module name, and path. If parentModuleMap is provided it will also normalize the name via require.normalize() @param {String} name the module name @param {String} [parentModuleMap] parent module map for the module name, used to resolve relative names. @param {Boole...
onError
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function takeGlobalQueue() { //Push all the globalDefQueue items into the context's defQueue if (globalDefQueue.length) { //Array splice in the values since the context code has a //local var ref to defQueue, so cannot just reassign the one //on co...
Internal method to transfer globalQueue items to this context's defQueue.
takeGlobalQueue
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function cleanRegistry(id) { //Clean up machinery used for waiting modules. delete registry[id]; delete enabledRegistry[id]; }
Internal method to transfer globalQueue items to this context's defQueue.
cleanRegistry
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function breakCycle(mod, traced, processed) { var id = mod.map.id; if (mod.error) { mod.emit('error', mod.error); } else { traced[id] = true; each(mod.depMaps, function (depMap, i) { var depId = depMap.id, ...
Internal method to transfer globalQueue items to this context's defQueue.
breakCycle
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function checkLoaded() { var map, modId, err, usingPathFallback, waitInterval = config.waitSeconds * 1000, //It is possible to disable the wait interval by using waitSeconds of 0. expired = waitInterval && (context.startTime + waitInterval) < new Date().getTim...
Internal method to transfer globalQueue items to this context's defQueue.
checkLoaded
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function callGetModule(args) { //Skip modules already defined. if (!hasProp(defined, args[0])) { getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]); } }
Checks if the module is ready to define itself, and if so, define it.
callGetModule
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function removeListener(node, func, name, ieName) { //Favor detachEvent because of IE9 //issue, see attachEvent/addEventListener comment elsewhere //in this file. if (node.detachEvent && !isOpera) { //Probably IE. If not it will throw an error, which will ...
Checks if the module is ready to define itself, and if so, define it.
removeListener
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function getScriptData(evt) { //Using currentTarget instead of target for Firefox 2.0's sake. Not //all old browsers will be supported, but this one was easy enough //to support and still makes sense. var node = evt.currentTarget || evt.srcElement; //Remove t...
Given an event from a script node, get the requirejs info from it, and then removes the event listeners on the node. @param {Event} evt @returns {Object}
getScriptData
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function intakeDefines() { var args; //Any defined modules in the global queue, intake them now. takeGlobalQueue(); //Make sure any remaining defQueue items get properly processed. while (defQueue.length) { args = defQueue.shift(); ...
Given an event from a script node, get the requirejs info from it, and then removes the event listeners on the node. @param {Event} evt @returns {Object}
intakeDefines
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function fn() { var ret; if (value.init) { ret = value.init.apply(global, arguments); } return ret || (value.exports && getGlobal(value.exports)); }
Set a configuration for the context. @param {Object} cfg config object to integrate.
fn
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function localRequire(deps, callback, errback) { var id, map, requireMod; if (options.enableBuildCallback && callback && isFunction(callback)) { callback.__requireJsBuild = true; } if (typeof deps === 'string') { ...
Set a configuration for the context. @param {Object} cfg config object to integrate.
localRequire
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function getInteractiveScript() { if (interactiveScript && interactiveScript.readyState === 'interactive') { return interactiveScript; } eachReverse(scripts(), function (script) { if (script.readyState === 'interactive') { return (interactiveScript = scri...
Does the request to load a module for the browser case. Make this a separate function to allow other environments to override it. @param {Object} context the require context to find state. @param {String} moduleName the name of the module. @param {Object} url the URL to the module.
getInteractiveScript
javascript
localForage/localForage
examples/require.js
https://github.com/localForage/localForage/blob/master/examples/require.js
Apache-2.0
function _init(stream) { stream.setMaxListeners(0); return stream; }
/*.js') .pipe(babel({ presets: ['es2015'], ignore: 'src/ui/vendor/*' })) .pipe(gulp.dest(appConfig.buildPath)); }); /* ------------------------------------------------ Sym Links ------------------------------------------------
_init
javascript
officert/mongotron
gulpfile.js
https://github.com/officert/mongotron/blob/master/gulpfile.js
MIT
function unlink(symlink, next) { fs.lstat(symlink, (lerr, lstat) => { if (lerr || !lstat.isSymbolicLink()) { return next(); } fs.unlink(symlink, () => { return next(); }); }); }
/*.js') .pipe(babel({ presets: ['es2015'], ignore: 'src/ui/vendor/*' })) .pipe(gulp.dest(appConfig.buildPath)); }); /* ------------------------------------------------ Sym Links ------------------------------------------------
unlink
javascript
officert/mongotron
gulpfile.js
https://github.com/officert/mongotron/blob/master/gulpfile.js
MIT
constructor(database, options) { if (!(database instanceof MongoDb)) console.error('Collection ctor - database is not an instance of MongoDb'); options = options || {}; var _this = this; _this.id = options.id; _this.name = options.name; _this.connection = options.connection; _this.database...
@param {Object} database - MongoDb object @param {Object} options @param {String} options.name - name of the collection @param {String} options.serverName - name of the server @param {String} options.databaseName - name of the database
constructor
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
find(query, options) { options = options || {}; let cursor = this._dbCollection.find(query, options); if (options.skip) cursor.skip(Number(options.skip)); cursor.limit(options.limit ? Number(options.limit) : DEFAULT_PAGE_SIZE); return new MongotronCursor(cursor); }
@param {Object} [query] - mongo query @param {Object} [options] - mongo query options
find
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
count(query, options) { query = query || {}; options = options || {}; return this._dbCollection.count(query, options); }
@param {Object} query - mongo query @param {Object} [options] - mongo query options
count
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
deleteMany(query, options) { return new Promise((resolve, reject) => { query = query || {}; options = options || {}; this._dbCollection.deleteMany(query, options, (err, result) => { if (err) return reject(err); return resolve(result); }); }); }
@param {Object} query - mongo query @param {Object} [options] - mongo query options
deleteMany
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
distinct(field, query) { if (!field) return Promise.reject(new errors.InvalidArugmentError('field is required')); query = query || {}; return Promise.fromCallback(callback => { this._dbCollection.distinct(field, query, callback); }); }
@param {String} field - mongo field, including dot-notated fields @param {Object} [query] - mongo query
distinct
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
aggregate(pipeline, options) { if (!_.isArray(pipeline)) return Promise.reject('pipeline must be an array'); options = options || {}; let stream = options.stream; delete options.stream; //always return as a cursor options.cursor = {}; let cursor = this._dbCollection.aggregate(pipeline, op...
@param {Object} [pipeline] - mongo pipeline @param {Object} [options] - mongo pipeline options
aggregate
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
updateMany(query, updates, options) { return new Promise((resolve, reject) => { if (!query) return reject(new errors.InvalidArugmentError('query is required')); if (!updates) return reject(new errors.InvalidArugmentError('updates is required')); options = options || {}; this._dbCollection.u...
@param {Object} query - mongo query @param {Object} updates - updates to apply @param {Object} [options] - mongo query options
updateMany
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
updateById(objectId, updates, options) { return new Promise((resolve, reject) => { if (!objectId) return reject(new errors.InvalidArugmentError('objectId is required')); if (!updates) return reject(new errors.InvalidArugmentError('updates is required')); options = options || {}; this._dbCol...
@param {Object} Mongo ObjectId @param {Object} updates - updates to apply @param {Object} [options] - mongo query options
updateById
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
updateOne(query, updates, options) { return new Promise((resolve, reject) => { if (!query) return reject(new errors.InvalidArugmentError('query is required')); if (!updates) return reject(new errors.InvalidArugmentError('updates is required')); options = options || {}; this._dbCollection.up...
@param {Object} query - mongo query @param {Object} updates - updates to apply @param {Object} [options] - mongo query options
updateOne
javascript
officert/mongotron
src/lib/entities/collection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/collection.js
MIT
constructor(options) { options = options || {}; var _this = this; _this.id = options.id; _this.name = options.name; _this.host = options.host; _this.port = options.port; _this.replicaSet = options.replicaSet; _this.databases = []; if (options.databaseName && !mongoUtils.isLocalHost...
@param {Object} options @param {String} options.name @param {String} [options.host] @param {String} [options.port] @param {Object} [options.replicaSet] @param {String} [options.replicaSet.name] @param {Array<Object>} [options.replicaSet.servers]
constructor
javascript
officert/mongotron
src/lib/entities/connection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/connection.js
MIT
get connectionString() { if (!this._connectionString) { this._connectionString = _getConnectionString(this); } return this._connectionString; }
@param {Object} options @param {String} options.name @param {String} [options.host] @param {String} [options.port] @param {Object} [options.replicaSet] @param {String} [options.replicaSet.name] @param {Array<Object>} [options.replicaSet.servers]
connectionString
javascript
officert/mongotron
src/lib/entities/connection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/connection.js
MIT
addDatabase(options) { options = options || {}; let existingDatabase = _.findWhere(this.databases, { name: options.name }); if (existingDatabase) return; let database = new Database({ id: options.id, name: options.name, host: options.host, port: options.port, a...
Add a new database to the connection @param {Object} options @param {String} options.name
addDatabase
javascript
officert/mongotron
src/lib/entities/connection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/connection.js
MIT
createDatabase(options) { options = options || {}; return new Promise((resolve, reject) => { if (!options) return reject(new Error('options is required')); if (!options.name) return reject(new Error('options.name is required')); let client = new MongoClient(); client.connect(this.conn...
Create a new database @param {Object} options @param {String} options.name @return Promise
createDatabase
javascript
officert/mongotron
src/lib/entities/connection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/connection.js
MIT
function _getDbsForLocalhostConnection(connection, next) { if (!connection) return next(new Error('connection is required')); if (!next) return next(new Error('next is required')); if (!mongoUtils.isLocalHost(connection.host)) return next(new Error('cannot get local dbs for non localhost connection')); var loc...
@function _getDbsForLocalhostConnection @param {Function} next - callback function @private
_getDbsForLocalhostConnection
javascript
officert/mongotron
src/lib/entities/connection.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/connection.js
MIT
constructor(options) { options = options || {}; this.id = options.id; this.name = options.name; //TODO: validate name doesn't contain spaces this.host = options.host; this.port = options.port; this.auth = options.auth; this.connection = options.connection; this.collections = []; i...
@param {Object} options @param {String} options.name - name of the database @param {String} options.host - host of the database, defaults to localhost @param {String} options.port - port of the database, defaults to 27017 @param {Object} options.auth - database auth info @param {String} options.auth.username - database...
constructor
javascript
officert/mongotron
src/lib/entities/database.js
https://github.com/officert/mongotron/blob/master/src/lib/entities/database.js
MIT
findById(id) { let _this = this; return new Promise((resolve, reject) => { if (!id) return reject(new errors.InvalidArugmentError('id is required')); return _this.list() .then((connections) => { return findConnectionById(id, connections); }) .then(resolve) ...
Find a connection by id @param {string} id - Id of the connection to find
findById
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
create(options) { let _this = this; return new Promise((resolve, reject) => { if (!options) return reject(new errors.InternalServiceError('options is required')); let connections; let newConnection; options.id = uuid.v4(); //assign a "unique" id return _this.list() .the...
Create a new connection @param {object} options @param {string} options.name - Connection name @param {string} options.host - Connection host @param {string} options.port - Connection port @param {string} [options.databaseName] - Database name @param {object} [options.replicaSet] - Replica set config @param {string} op...
create
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
update(id, updatedConnection) { let _this = this; let connections; return new Promise((resolve, reject) => { if (!id) return reject(new errors.InvalidArugmentError('id is required')); if (!updatedConnection) return reject(new errors.InvalidArugmentError('updatedConnection is required')); ...
Update a connection by id @param {string} id - id of the connection to update @param {object} updates - hash of updates to apply to the connection @param {string} [updates.name] - connection name @param {string} [updates.host] - Connection host @param {string} [updates.port ]- Connection port @param {string} [updates.d...
update
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
delete(id) { var _this = this; return new Promise((resolve, reject) => { if (!id) return reject(new errors.InvalidArugmentError('id is required')); return _this.list() .then((connections) => { return findConnectionById(id, connections) .then(function(connection) { ...
Delete a connection by id @param {string} id - id of the connection to delete
delete
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
existsByName(name) { var _this = this; return _this.list() .then((connections) => { return new Promise((resolve) => { var existingConnection = _.findWhere(connections, { name: name }); return resolve(existingConnection ? true : false); }); }...
Check if a connection exists by name @param {String} name
existsByName
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function readConfigFile() { return fileUtils.readJsonFile(DB_CONNECTIONS); }
Check if a connection exists by name @param {String} name
readConfigFile
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function writeConfigFile(data) { return fileUtils.writeJsonFile(DB_CONNECTIONS, data); }
Check if a connection exists by name @param {String} name
writeConfigFile
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function getConnectionInstances() { return readConfigFile() .then((connectionConfigs) => { return new Promise((resolve) => { return resolve(connectionConfigs && connectionConfigs.length ? connectionConfigs.map(generateConnectionInstanceFromConfig) : []); }); }); }
Check if a connection exists by name @param {String} name
getConnectionInstances
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function generateConnectionInstanceFromConfig(connectionConfig) { var newConn = new Connection({ id: connectionConfig.id || uuid.v4(), name: connectionConfig.name, host: connectionConfig.host, port: connectionConfig.port, replicaSet: connectionConfig.replicaSet }); _.each(connectionConfig.dat...
Check if a connection exists by name @param {String} name
generateConnectionInstanceFromConfig
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function convertConnectionInstancesIntoConfig(connections) { return new Promise((resolve) => { let configs = connections.map(convertConnectionInstanceIntoConfig); return resolve(configs); }); }
Check if a connection exists by name @param {String} name
convertConnectionInstancesIntoConfig
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function convertConnectionInstanceIntoConfig(connection) { //unique id's are added to the entities to emulate //storing them in a real database that would assign unique ids //the app relies on the various entities to have unique ids so //until I change to storing these in something that assigns ids //we have ...
Check if a connection exists by name @param {String} name
convertConnectionInstanceIntoConfig
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function findConnectionById(connectionId, connections) { return new Promise((resolve, reject) => { var foundConnection = _.findWhere(connections, { id: connectionId }); if (foundConnection) { return resolve(foundConnection); } else { return reject(new errors.ObjectNotFoundError('Con...
Check if a connection exists by name @param {String} name
findConnectionById
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function createConnection(options) { return new Promise((resolve) => { var newConn = new Connection(options); return resolve(newConn); }); }
Check if a connection exists by name @param {String} name
createConnection
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function removeConnection(connection, connections) { return new Promise((resolve) => { var index = connections.indexOf(connection); connections.splice(index, 1); return resolve(connections); }); }
Check if a connection exists by name @param {String} name
removeConnection
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
function updateConnection(originalConnection, updatedConnection, connections) { return new Promise((resolve) => { // connection = _.extend(connection, options); let index = connections.indexOf(originalConnection); connections.splice(index, 1, updatedConnection); return resolve(connections); }); }
Check if a connection exists by name @param {String} name
updateConnection
javascript
officert/mongotron
src/lib/modules/connection/repository.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/repository.js
MIT
findById(id) { return connectionRepository.findById(id); }
Find a connection by id @param {string} id - Id of the connection to find
findById
javascript
officert/mongotron
src/lib/modules/connection/service.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/service.js
MIT
create(options) { //map it to a new object so nothing unexpected can be passed in and saved let newConnection = { name: options.name, host: options.host, port: options.port, databaseName: options.databaseName, replicaSet: options.replicaSet, auth: options.auth }; ret...
Create a new connection @param {object} options @param {string} options.name - Connection name @param {string} options.host - Connection host @param {string} options.port - Connection port @param {string} [options.databaseName] - Database name @param {object} [options.replicaSet] - Replica set config @param {string} op...
create
javascript
officert/mongotron
src/lib/modules/connection/service.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/service.js
MIT
update(id, updates) { let _this = this; return new Promise((resolve, reject) => { if (!id) return reject(new errors.InvalidArugmentError('id is required')); if (!updates) return reject(new errors.InvalidArugmentError('updates is required')); _this.findById(id) .then((connection) => {...
Update a connection by id @param {string} id - id of the connection to update @param {object} updates - hash of updates to apply to the connection @param {string} [updates.name] - connection name @param {string} [updates.host] - Connection host @param {string} [updates.port ]- Connection port @param {string} [updates.d...
update
javascript
officert/mongotron
src/lib/modules/connection/service.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/service.js
MIT
delete(id) { return connectionRepository.delete(id); }
Delete a connection by id @param {string} id - id of the connection to delete
delete
javascript
officert/mongotron
src/lib/modules/connection/service.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/service.js
MIT
function _applyConnectionUpdatesPreValidation(connection, updates) { return new Promise((resolve) => { if ('name' in updates) connection.name = updates.name; if ('host' in updates) { connection.host = updates.host; delete connection.replicaSet; if (mongoUtils.isLocalHost(updates.host)) { ...
Validate updates to a connection @param {Connection} connection - connection instance @param {object} updates - hash of updates to apply to validate @private
_applyConnectionUpdatesPreValidation
javascript
officert/mongotron
src/lib/modules/connection/service.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/service.js
MIT
function _applyConnectionUpdatesPostValidation(connection, updates) { return new Promise((resolve) => { let db = connection.databases && connection.databases.length ? connection.databases[0] : null; if (db) { if ('auth' in updates) { if (!updates.auth) { delete db.auth; } els...
Validate updates to a connection @param {Connection} connection - connection instance @param {object} updates - hash of updates to apply to validate @private
_applyConnectionUpdatesPostValidation
javascript
officert/mongotron
src/lib/modules/connection/service.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/service.js
MIT
validateCreate(data) { return new Promise((resolve, reject) => { _baseValidate(data) .then(resolve) .catch(reject); }); }
Validate a connection for creating @param {object} data
validateCreate
javascript
officert/mongotron
src/lib/modules/connection/validator.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/validator.js
MIT
validateUpdate(data) { return new Promise((resolve, reject) => { _baseValidate(data) .then(resolve) .catch(reject); }); }
Validate a connection for updating @param {object} data
validateUpdate
javascript
officert/mongotron
src/lib/modules/connection/validator.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/validator.js
MIT
function _baseValidate(data) { return new Promise((resolve, reject) => { if (!data.name) return reject(new errors.InvalidArugmentError('connection.name is required')); if (data.replicaSet) { if (!data.replicaSet.name) return reject(new errors.InvalidArugmentError('data.replicaSet.name is required')); ...
Validate a connection for updating @param {object} data
_baseValidate
javascript
officert/mongotron
src/lib/modules/connection/validator.js
https://github.com/officert/mongotron/blob/master/src/lib/modules/connection/validator.js
MIT