Ejemplo n.º 1
0
const camelCaseConvert = (input, opts) => {
	opts = Object.assign({
		deep: false
	}, opts);

	const exclude = opts.exclude;

	return mapObj(input, (key, val) => {
		if (!(exclude && has(exclude, key))) {
			if (cache.has(key)) {
				key = cache.get(key);
			} else {
				const ret = camelCase(key);

				if (key.length < 100) { // Prevent abuse
					cache.set(key, ret);
				}

				key = ret;
			}
		}

		return [key, val];
	}, {deep: opts.deep});
};
Ejemplo n.º 2
0
 Object.keys(swagger.paths).forEach(function (path) {
   const route = swagger.paths[path]
   const base = swagger.basePath || ''
   router.set(join(base, createPath(path, options)), map(route, (method, data) => [
     method.toUpperCase(),
     Route(path, method, data)
   ]))
 })
Ejemplo n.º 3
0
module.exports = function (input, options) {
	options = options || {};

	var exclude = options.exclude || [];

	return mapObj(input, function (key, val) {
		key = has(exclude, key) ? key : camelCase(key);
		return [key, val];
	});
};
Ejemplo n.º 4
0
function getElementProps(props) {
  return map(props, function(key, val) {
    var method = LIFECYCLE_METHODS[key];
    if (method) {
      key = method.name;
      val = method.wrapper ? method.wrapper(val) : val;
    }
    return [key, val];
  });
}
Ejemplo n.º 5
0
module.exports = obj => {
	return mapObject(obj, (key, value) => {
		if (value && typeof value.toBSON === 'function') {
			value = value.toBSON();
		}

		if (Array.isArray(value) && value[0] && typeof value[0].toBSON === 'function') {
			value = value.map(item => item.toBSON());
		}

		return [key, value];
	});
};
Ejemplo n.º 6
0
  const resolver = (obj) => {
    if (isArray(obj)) {
      return obj.map(value => resolvePath(basepath, value));
    }

    if (isObject(obj)) {
      return mapObject(obj, (key, value) => [key, resolvePath(basepath, value)]);
    }

    if (isString(obj) && (obj.startsWith('.') || obj.startsWith('..'))) {
      return join(basepath, obj);
    }

    return obj;
  };
Ejemplo n.º 7
0
    .map(function (node) {
      var requireString = node.arguments[0].value.toString();
      var replaceRequireFunc = null;

      mapObject(replacements, function (moduleName, requireFunc) {
        if (requireString === moduleName ||
            requireString.indexOf(moduleName + "/") === 0) {
          replaceRequireFunc = requireFunc;
        }

        return requireFunc;
      });

      if (replaceRequireFunc) {
        return extend(node, {
          replacement: replaceRequireFunc + '("' + requireString + '")'
        });
      }

      return node;
    })
Ejemplo n.º 8
0
	Examples
		$ pwa-manifest ./app --icons=./logo.png
		$ pwa-manifest ./app ./app/images/icons --icons=./logo.png
		$ pwa-manifest --name='My Progressive Web App' --short_name='My PWA' --display=fullscreen --background_color=#fefefe --theme_color=#f44336 --orientation=any --direction=portrait --icons=./images/logo.png
		$ pwa-manifest --interactive
`]);

// set manifest destination
const manifestDest = cli.input[0] ? path.resolve(process.cwd(), cli.input[0].replace(/manifest.json$/, '')) : process.cwd();

// set icons destination
const iconsDest = cli.input[1] ? path.resolve(process.cwd(), cli.input[1]) : manifestDest;

// determine interactive mode or not
const ask = cli.flags.interactive ? inquirer.ask() : Promise.resolve(
	mapObj(cli.flags, (key, value) => [decamelize(key, '_'), value])
);

// fiter image by size
const filterImageSize = max => filterObj(members.icons, size => size <= max);

// prepare icons it can be from online and local
const prepareIcon = answers => {
	return new Promise((resolve, reject) => {
		if (!answers.icons) {
			resolve(answers);
		} else if (/^https?/.test(answers.icons)) {
			const url = answers.icons;
			const dir = rndTmpdir('pwa-manifest');

			mkdirp.sync(dir);
Ejemplo n.º 9
0
module.exports = function (opts, minimistOpts) {
    loudRejection();

    if (Array.isArray(opts) || typeof opts === 'string') {
        opts = {help: opts};
    }

    opts = objectAssign({
        pkg: readPkgUp.sync({
            cwd: parentDir,
            normalize: false
        }).pkg,
        argv: process.argv.slice(2)
    }, opts);

    minimistOpts = objectAssign({}, minimistOpts);

    minimistOpts.default = mapObj(minimistOpts.default || {}, function (key, value) {
        return [decamelize(key, '-'), value];
    });

    if (Array.isArray(opts.help)) {
        opts.help = opts.help.join('\n');
    }

    var pkg = typeof opts.pkg === 'string' ? require(path.join(parentDir, opts.pkg)) : opts.pkg;
    var argv = minimist(opts.argv, minimistOpts);
    var help = redent(trimNewlines(opts.help || ''), 2);

    normalizePackageData(pkg);

    process.title = pkg.bin ? Object.keys(pkg.bin)[0] : pkg.name;

    var description = opts.description;
    if (!description && description !== false) {
        description = pkg.description;
    }

    help = (description ? '\n  ' + description + '\n' : '') + (help ? '\n' + help : '\n');

    var showHelp = function (code) {
        console.log(help);
        process.exit(code || 0);
    };

    if (argv.version && opts.version !== false) {
        console.log(typeof opts.version === 'string' ? opts.version : pkg.version);
        process.exit();
    }

    if (argv.help && opts.help !== false) {
        showHelp();
    }

    var _ = argv._;
    delete argv._;

    return {
        input: _,
        flags: camelcaseKeys(argv),
        pkg: pkg,
        help: help,
        showHelp: showHelp
    };
};
Ejemplo n.º 10
0
    --json: Print out query result in JSON

  Examples,
    $ if-got categories
    $ if-got categories --count=30 --json
    $ if-got icons search --query=app --maximum_size=512 --json --> search.json
    $ if-got icons 495310
    $ if-got iconsets romance
    $ if-got iconsets 28238
    $ if-got styles --count=5
    $ if-got styles/3d
    $ if-got users/ragingwind
`]);

const path = cli.input[0];
const subpath = cli.input[1];
const resource = `${path}${subpath ? `/${subpath}` : ''}`;
const opts = {
	query: mapObj(cli.flags, (o, v) => [decamelize(o, '_'), v])
};

if (!path || subpath && subpath === 'search' && !cli.flags.query) {
	cli.showHelp();
}

got(resource, opts).then(r => {
	console.log(cli.flags.json ? JSON.stringify(r.body, '', 2) : simplify(r.body, resource, opts.query));
}).catch(e => {
	console.log(e.toString());
});
Ejemplo n.º 11
0
/*
 * 路径的转换
 */
 import path from 'path';
 import mapObj from 'map-obj';
 import dirs from './dirs';

 const resolve = path.resolve;
// 项目根路径
 const base = [resolve(__dirname, '..')];
 const root = (...args) => resolve.apply(resolve, [...base, ...args]);
 const entries = mapObj(dirs, (k, v) => [k, root.bind(null, v)]);

 export default { root, ...entries };
Ejemplo n.º 12
0
import mapObj from 'map-obj'
import resolve from './resolve'

// 执行一遍 resolve 对象
/*
 * 生成 类似
 * {
 *  root: '/',
 *  src: '/src'
 * }
 * 上面应该是绝对路径
 */
const rootSiblings = mapObj(resolve, (k, v) => [k, v('')])
/**
 * 生成 一些路径的配置
 *
 */
export default {
  ...rootSiblings, // root, (bin, src, dist)(dirs 中的)

  client: resolve.src('client'),

  // public: resolve.dist('public'),
  //
  // scripts: resolve.src('scripts'),
  styles: resolve.assets('styles'),
  // templates: resolve.src('templates'),
  //
  // // 资产的路径
  // assets: {
  //   root: resolve.src('assets'),
Ejemplo n.º 13
0
module.exports = function (obj) {
    return mapObj(obj, function (key, val) {
        return [camelCase(key), val];
    });
};
Ejemplo n.º 14
0
module.exports = function (obj) {
  return mapObj(obj, function (key, value) {
    return ['_' + key, value]
  })
}
module.exports = function(value) {
	var result = {};
	var values = normalizeUrl(normalizeColor(value))
		.replace(/\//, ' / ')
		.split(/\s+/);

	var first = values[0];

	if(values.length === 1 && KEYWORD.test(first)) {
		return {
			'background-attachment': first,
			'background-clip': first,
			'background-image': first,
			'background-repeat': first,
			'background-color': first,
			'background-position': first,
			'background-size': first
		};
	}

	for(var i = 0; i < values.length; i++) {
		var v = values[i];

		if(ATTACHMENT.test(v)) {
			if(result.attachment) return;
			result.attachment = v;
		} else if(BOX.test(v)) {
			if(result.clip) return;
			result.clip = v;
		} else if(IMAGE.test(v)) {
			if(result.image) return;
			result.image = v;
		} else if(REPEAT_SINGLE.test(v)) {
			if(result.repeat) return;
			result.repeat = v;
		} else if(REPEAT_DOUBLE.test(v)) {
			if(result.repeat) return;

			var n = values[i + 1];

			if(n && REPEAT_DOUBLE.test(n)) {
				v += ' ' + n;
				i++;
			}

			result.repeat = v;
		} else if(isColor(v)) {
			if(result.color) return;
			result.color = v;
		} else if(POSITION_HORIZONTAL.test(v) || POSITION_VERTICAL.test(v) || isLength(v)) {
			if(result.position) return;

			var n = values[i + 1];
			var isHorizontal = POSITION_HORIZONTAL.test(v) || isLength(v);
			var isVertical = POSITION_VERTICAL.test(n) || isLength(n);

			if(isHorizontal && isVertical) {
				result.position = v + ' ' + n;
				i++;
			} else {
				result.position = v;
			}

			v = values[i + 1];

			if(v === '/') {
				i += 2;
				v = values[i];

				if(SIZE_SINGLE.test(v)) {
					result.size = v;
				} else if(v === 'auto' || isLength(v)) {
					n = values[i + 1];

					if(n === 'auto' || isLength(n)) {
						v += ' ' + n;
						i++;
					}

					result.size = v;
				} else {
					return;
				}
			}
		} else {
			return;
		}
	}

	return map(result, function(key, value) {
		return ['background-' + key, value];
	});
};