module.exports = (options, formData) => defaultsDeep({ formData: formData, headers: { "X-Atlassian-Token": "no-check" }, json: false }, options);
group.test('User found & Session valid', function (t) { mockCouchDbGetUser.reply(200, { name: 'pat-doe', roles: [ 'id:userid123', 'mycustomrole' ], profile: { fullName: 'pat Doe', email: '*****@*****.**' }, salt: 'salt123' }) var options = defaultsDeep({ url: '/session?include=account.profile' }, routeOptions) var sessionWithProfileResponse = require('../../fixtures/session-with-profile-response.json') server.inject(options, function (response) { delete response.result.meta t.is(response.statusCode, 200, 'returns 200 status') t.deepEqual(response.result, sessionWithProfileResponse, 'returns the right content') t.end() }) })
EmberApp.prototype.import = function(asset, options) { var assetPath = this._getAssetPath(asset); if (!assetPath) { return; } options = defaultsDeep(options || {}, { type: 'vendor', prepend: false }); var directory = path.dirname(assetPath); var subdirectory = directory.replace(new RegExp('^vendor/|' + this.bowerDirectory), ''); var extension = path.extname(assetPath); if (!extension) { throw new Error('You must pass a file to `app.import`. For directories specify them to the constructor under the `trees` option.'); } this._import( assetPath, options, directory, subdirectory, extension ); };
function AttributeEvaluator(opts) { opts = defaults(opts || {}, defaultOpts.attrEvaluator); this.contexts = {}; this.actions = {}; for (var attrKey in opts.attrNames) { var attrName = opts.attrNames[attrKey]; this.addAction(attrName, opts.attrActions[attrKey]); } };
const parseNode = (node) => { const Component = MJMLElementsCollection[node.tagName] return !Component ? {} : { // copy all existing props, applying defaults ...defaultsDeep(node, Component.defaultMJMLDefinition), // do same to children children: (node.children || []).map(parseNode) } }
({ locale, messages = {} }) => { const polyglot = new Polyglot({ locale, phrases: defaultsDeep({}, messages, defaultMessages), }); return { locale, translate: polyglot.t.bind(polyglot), }; }
/** * Constructor for a generic tab object * @param {Object} args The arguments for the tab. * @constructor */ function GenericTab( args ) { defaultsDeep( args, defaultArguments ); this.label = args.label; this.active = args.active; this.hideable = args.hideable; this.classes = args.classes; this.onActivate = args.onActivate; this.afterActivate = args.afterActivate; }
constructor (options = {}) { if (!(arguments.length === 2 && _isString(arguments[0]) && _isArray(arguments[1])) && !(arguments.length === 1 && (_isPlainObject(arguments[0]) || _isString(arguments[0])))) { throw new Error('Invalid argument, initialize Devour with an object.') } let defaults = { middleware: jsonApiMiddleware, logger: true, resetBuilderOnCall: true, auth: {}, trailingSlash: {collection: false, resource: false} } let deprecatedConstructors = (args) => { return (args.length === 2 || (args.length === 1 && _isString(args[0]))) } if (deprecatedConstructors(arguments)) { defaults.apiUrl = arguments[0] if (arguments.length === 2) { defaults.middleware = arguments[1] } } options = _defaultsDeep(options, defaults) let middleware = options.middleware this._originalMiddleware = middleware.slice(0) this.middleware = middleware.slice(0) this.headers = {} this.axios = axios this.auth = options.auth this.apiUrl = options.apiUrl this.models = {} this.deserialize = deserialize this.serialize = serialize this.builderStack = [] this.resetBuilderOnCall = !!options.resetBuilderOnCall if (options.pluralize === false) { this.pluralize = s => s this.pluralize.singular = s => s } else if ('pluralize' in options) { this.pluralize = options.pluralize } else { this.pluralize = pluralize } this.trailingSlash = options.trailingSlash === true ? _forOwn(_clone(defaults.trailingSlash), (v, k, o) => { _set(o, k, true) }) : options.trailingSlash options.logger ? Logger.enable() : Logger.disable() if (deprecatedConstructors(arguments)) { Logger.warn('Constructor (apiUrl, middleware) has been deprecated, initialize Devour with an object.') } }
this.addEventListener(input, 'input', (event) => { if (input.value) { let options = { input: input.value } autoComplete.getPlacePredictions(_defaultsDeep(options, autoCompleteOptions), (suggestions, status) => { this.autoCompleteDisplaySuggestions(suggestions, status, suggestionContainer, input); }); } else { this.autoCompleteCleanSuggestions(suggestionContainer); suggestionContainer.style.display = 'none'; } });
Model.inherits = function(Constructor, options){ var Super = this; if (typeof Constructor !== 'function') { options = Constructor; Constructor = function ExtendedModel(data){ return Super.call(this, data) } } util.inherits(Constructor, Super); assign(Constructor, Super); options = defaultsDeep({}, options || {}, Super.rawOptions); Constructor.rawOptions = cloneDeep(options); for (var name in methods) { options[name] = defaultsDeep({}, options[name] || {}, options); } Constructor.options = options; Constructor.req = options.req; assign(Constructor, methods); assign(Constructor, rawMethods); assign(Constructor, realtimeMethods); // bind if (options.bind) bindAll(Constructor, keys(methods).concat(keys(rawMethods))); // realtime if (options.realtime) { if (options.realtime === true || options.realtime.inserted) setWebSocket(Constructor, 'inserted'); if (options.realtime === true || options.realtime.updated) setWebSocket(Constructor, 'updated'); if (options.realtime === true || options.realtime.saved) setWebSocket(Constructor, 'saved'); if (options.realtime === true || options.realtime.deleted) setWebSocket(Constructor, 'deleted'); } return Constructor; }
let panels = mapValues(configs, (panel, name) => { let type = panel.type || 'box' let widget = blessed[type] || blessed.box let config = pick(panel, 'top', 'left', 'height', 'width', 'label', 'border', 'style') if (panel.borderStyles) { config = defaults(config, borderStyles(panel.borderStyles)) } let element = widget(config) screen.append(element) return element })
function GitHubApi (options) { const defaults = defaultsDeep(parseClientOptions(options), ENDPOINT_DEFAULTS) const hook = new Hook() const api = { // NOTE: github.hook, github.plugin and github.request are experimental APIs // at this point and can change at any time hook, plugin: (pluginFunction) => pluginFunction(api), request: (options) => api.hook('request', defaultsDeep(options, defaults), request) } PLUGINS.forEach(api.plugin) return api }
test('DELETE /session?include=account.profile', function (group) { var options = defaultsDeep({ url: '/session?include=account.profile' }, routeOptions) getServer(function (error, server) { if (error) { group.error(error) group.end() return } group.test('User found', function (subGroup) { function couchdbUserFoundMock () { return couchdbGetUserMock.reply(200, { name: 'pat-doe', roles: [ 'id:userid123', 'mycustomrole' ], salt: 'salt123', profile: { fullName: 'pat Doe', email: '*****@*****.**' } }) } subGroup.test('Session valid', function (t) { var couchdb = couchdbUserFoundMock() var sessionWithProfileResponse = require('../../fixtures/session-with-profile-response.json') server.inject(options, function (response) { t.is(couchdb.pendingMocks()[0], undefined, 'CouchDB received request') delete response.result.meta t.is(response.statusCode, 200, 'returns 200 status') t.deepEqual(response.result, sessionWithProfileResponse, 'returns the right content') t.end() }) }) subGroup.end() }) group.end() }) })
getServer(function (error, server) { if (error) { t.error(error) t.end() return } t.plan(1) var options = defaultsDeep({ url: '/session?include=foobar' }, routeOptions) server.inject(options, function (response) { t.is(response.statusCode, 400, 'returns 400 status') }) })
group.test('User is admin', function (t) { var requestOptions = defaultsDeep({ headers: { // calculateSessionId('admin', '1081b31861bd1e91611341da16c11c16a12c13718d1f712e', 'secret', 1209600) authorization: 'Bearer YWRtaW46MTI3NTAwOh08V1EljPqAPAnv8mtxWNF87zdW' } }, routeOptions) var sessionAdminResponse = require('../../fixtures/session-admin-response.json') server.inject(requestOptions, function (response) { delete response.result.meta t.is(response.statusCode, 200, 'returns 200 status') t.deepEqual(response.result, sessionAdminResponse, 'returns the right content') t.end() }) })
subGroup.test('Session invalid', function (t) { var couchdb = couchdbUserFoundMock() var requestOptions = defaultsDeep({ headers: { // Token calculated with invalid salt (salt456) authorization: 'Bearer cGF0LWRvZToxMjc1MDA6YMtzOJDSC7iTA4cB2kjfjqbfk1Y' } }, routeOptions) server.inject(requestOptions, function (response) { t.is(couchdb.pendingMocks()[0], undefined, 'CouchDB received request') t.is(response.statusCode, 404, 'returns 404 status') t.is(response.result.errors.length, 1, 'returns one error') t.is(response.result.errors[0].title, 'Not Found', 'returns "Not Found" error') t.end() }) })
constructor (conf, data) { if (!data) { logger.log(2, 'no layout data', '') } this.conf = defaultsDeep(conf, cloneDeep(defaultConf)) this.data = data const agg = reduce(data, (aggregator, block) => { block.offset = aggregator.offset aggregator.blocks[block.id] = { label: block.label, len: block.len, color: block.color, offset: aggregator.offset } aggregator.offset += block.len return aggregator }, {blocks: {}, offset: 0}) this.blocks = agg.blocks this.size = agg.offset // thanks to sum of blocks' length, compute start and end angles in radian forEach(this.data, (block, index) => { this.blocks[block.id].start = block.offset / this.size * (2 * Math.PI - this.data.length * this.conf.gap) + index * this.conf.gap this.blocks[block.id].end = (block.offset + block.len) / this.size * (2 * Math.PI - this.data.length * this.conf.gap) + index * this.conf.gap block.start = block.offset / this.size * (2 * Math.PI - this.data.length * this.conf.gap) + index * this.conf.gap block.end = (block.offset + block.len) / this.size * (2 * Math.PI - this.data.length * this.conf.gap) + index * this.conf.gap }) }
function borderStyles(options = {}) { defaults(options, { type: 'line', color: 'white' }) let { type, color } = options return { border: { type }, style: { border:{ fg: color } } } }
/** EmberApp is the main class Ember CLI uses to manage the Broccoli trees for your application. It is very tightly integrated with Broccoli and has an `toTree()` method you can use to get the entire tree for your application. Available init options: - es3Safe, defaults to `true`, - storeConfigInMeta, defaults to `true`, - autoRun, defaults to `true`, - outputPaths, defaults to `{}`, - minifyCSS, defaults to `{enabled: !!isProduction,options: { relativeTo: 'assets' }}, - minifyJS, defaults to `{enabled: !!isProduction}, - sourcemaps, defaults to `{}`, - trees, defaults to `{},` - jshintrc, defaults to `{},` - vendorFiles, defaults to `{}` @class EmberApp @constructor @param {Object} [defaults] @param {Object} [options={}] Configuration options */ function EmberApp(defaults, options) { if (arguments.length === 0) { options = {}; } else if (arguments.length === 1) { options = defaults; } else { defaultsDeep(options, defaults); } this._initProject(options); this.name = options.name || this.project.name(); this.env = EmberApp.env(); this.isProduction = (this.env === 'production'); this.registry = options.registry || p.defaultRegistry(this); this.bowerDirectory = this.project.bowerDirectory; this._initTestsAndHinting(options); this._initOptions(options); this._initVendorFiles(); this._styleOutputFiles = {}; this._scriptOutputFiles = {}; this.legacyFilesToAppend = []; this.vendorStaticStyles = []; this.otherAssetPaths = []; this.legacyTestFilesToAppend = []; this.vendorTestStaticStyles = []; this.trees = this.options.trees; this.populateLegacyFiles(); p.setupRegistry(this); this._notifyAddonIncluded(); if (!this._addonInstalled('loader.js') && !this.options._ignoreMissingLoader) { throw new SilentError('The loader.js addon is missing from your project, please add it to `package.json`.'); } }
subGroup.test('Session invalid', function (t) { mockCouchDbGetUser.reply(200, { name: 'pat-doe', roles: [ 'id:userid123', 'mycustomrole' ], salt: 'salt123' }) var requestOptions = defaultsDeep({ headers: { // Token calculated with invalid salt (salt456) authorization: 'Bearer cGF0LWRvZToxMjc1MDA6YMtzOJDSC7iTA4cB2kjfjqbfk1Y' } }, routeOptions) server.inject(requestOptions, function (response) { t.is(response.statusCode, 401, 'returns 401 status') t.is(response.result.errors.length, 1, 'returns one error') t.is(response.result.errors[0].title, 'Unauthorized', 'returns "Session invalid" error') t.end() }) })
group.test('username is not a valid email', function (t) { var options = defaultsDeep({ payload: { data: { attributes: { username: '******' } } } }, routeOptions) server.inject(options, function (response) { t.is(response.statusCode, 409, 'returns 409 status') t.is(response.result.errors.length, 1, 'returns one error') t.is(response.result.errors[0].title, 'Conflict', 'returns "Conflict" error') // TODO: fix Joi’s standard error messages. `.detail` currently is // child "data" fails because [child "attributes" fails because // [child "username" fails because ["username" must be a valid email]]] // t.is(response.result.errors[0].detail, 'username (foo) is invalid email address') t.end() }) })
* This profile is used to cache webpack's module * contexts for external library and framework type * dependencies which will usually not change often enough * to warrant building them from scratch every time we use * the webpack process. */ const { join } = require('path'); const defaults = require('lodash/defaultsDeep'); const webpack = require('webpack'); const pkg = require(join(process.cwd(), 'package.json')); const dllPlugin = require('../config').dllPlugin; if (!pkg.dllPlugin) { process.exit(0); } const dllConfig = defaults(pkg.dllPlugin, dllPlugin.defaults); const outputPath = join(process.cwd(), dllConfig.path); module.exports = require('./webpack.base.babel')({ context: process.cwd(), entry: dllConfig.dlls ? dllConfig.dlls : dllPlugin.entry(pkg), devtool: 'eval', output: { filename: '[name].dll.js', path: outputPath, library: '[name]', }, plugins: [ new webpack.DllPlugin({ name: '[name]', path: join(outputPath, '[name].json'),
request: (options) => api.hook('request', defaultsDeep(options, defaults), request)
constructor(props) { super(defaultsDeep(props, Pagination.defaultProps)); this.handleClick = this.handleClick.bind(this); }
import defaultsDeep from 'lodash/defaultsDeep'; import base from './base'; export default defaultsDeep({ name: 'development', }, base);
import defaultsDeep from 'lodash/defaultsDeep'; let OPTIONS = {}; const emitError = function({ response }) { __guardMethod__(OPTIONS.handlers, 'onFail', o => o.onFail({ response })); return response; }; const Networking = { setOptions(options) { return OPTIONS = options; }, updateOptions(options) { return defaultsDeep(OPTIONS, options); }, perform(opts) { return axios(extend({}, OPTIONS != null ? OPTIONS.xhr : undefined, opts)).catch(function(err) { if (!opts.silenceErrors) { emitError(err); } return err.response; }); }, }; export default Networking; function __guardMethod__(obj, methodName, transform) { if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') { return transform(obj, methodName);
import defaultsDeep from 'lodash/defaultsDeep'; import base from './base'; export default defaultsDeep({ googleAnalytics: { clientID: '' } }, base);
module.exports = function delayDebug(config){ if(~process.argv.indexOf('--delaydebug')){ // Set the defaults defaults(config,{ delaydebug: { "web-port" : 8088 ,"web-host" : "0.0.0.0" ,"debug-port" : 5858 ,"save-live-edit" : true ,"preload" : false ,"hidden" : ["node_modules"] ,"stack-trace-limit" : 50 } }); var // Flatten the config object into a list of arugments cmdArgs = Object.keys(config.delaydebug) .filter(function(key){ return config.delaydebug[key]; }) .map(function(key){ // Get teh value var value = config.delaydebug[key]; // If the value is an array then if(Array.isArray(value)) value = value.map(function(it){return '--' + key + ' ' + it;}).join(' '); else value = '--' + key + ' ' + value; // Return the argument value return value; }) .join(' ') // Define the command ,cmd = process.execPath+" "+path.join(require.resolve('node-inspector'),'..','bin','inspector.js ' + cmdArgs) ; // Notify about the delaydebug command console.log('DELAYDEBUG ===> ', cmd); child.exec(cmd // TODO: Make this handling nicer ,function(error, stdout, stderr){ console.log('stdout:'+ stdout); console.log('stderr:'+ stderr); if( error !== null ) { console.log('exec error:'+ error); } } ); // Start debugging the current process (undocumented feature, might break in the future) process._debugProcess(process.pid); // To still run in old versions of javascript using a array.join var msg = [ '' ,'==============================' ,'Node Inspector will be started in 2 seconds. Point your browser to:' ,'http://'+(config.delaydebug['web-host'])+':'+config.delaydebug['web-port']+'?port='+config.delaydebug['debug-port']+' (or the one you configured)' ,'You will not be able to browse to your app until you have browsed to node inspector' ,'If you edit and save files through the inspector, there is no need to restart this app' ,'If using nodemon, you should disable auto reload and depend on typing "rs" on the console' ,'Provide a file path to delayDebug to change node inspector configuration' ,'Sometimes you might need to use the "pause" button on the debugger and then "continue" in order to allow the server process continue' ,'==============================' ,'' ] // Output the information console.log(msg.join("\n")); } }
}, delete (uri, options = {}) { return this._wrap(fetch(this._url(uri), { method: 'delete' })) }, log (response) { console.log(response) return response }, _jsonOptions (options, body, method) { defaultsDeep(options, { method: method || 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(body) }) return options }, _wrap (request) { return request.then(this._checkStatus).then(this._parseJson) }, _checkStatus (response) { if (response.status >= 200 && response.status < 300) { return response } else {
} // check if source was defined in run params assert(!isUndefined(args.src), '--src was not defined!'); // check if source file exists and is a JSON file const src = path.resolve(args.src); assert(fileExists(src), `${src} is not a file!`); assert(isJsonFileValid(src), `${src} is not a valid JSON file!`); // check if destination file is in run params assert(!isUndefined(args.dest), '--dest was not defined!'); assert(isObject(args.params), '--params was not defined!'); const dest = path.resolve(args.dest); const json = defaultsDeep(args.params, getJsonContent(src)); // write dest to file fs.writeFileSync(dest, JSON.stringify(json, null, 2)); console.log(`Successfully merged to ${colors.green(dest)} file`); /** * @param {string} destination * @returns {boolean} */ function fileExists(destination) { try { return fs.statSync(destination).isFile(); } catch (e) { return false; }