How to use the utility.has function in utility

To help you get started, we’ve selected a few utility examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-modules / serialize-json / lib / encoder.js View on Github external
ast.push(this._buildAst(item));
      }
      return ast;
    }
    if (is.error(obj)) {
      ast = [ '#' ];
      ast.push(this._buildAst('message'));
      ast.push(this._buildAst(obj.message));
      ast.push(this._buildAst('stack'));
      ast.push(this._buildAst(obj.stack));
    } else {
      ast = [ '$' ];
    }
    for (const key in obj) {
      // support object without prototype, like: Object.create(null)
      if (!utility.has(obj, key)) {
        continue;
      }
      ast.push(this._buildAst(key));
      ast.push(this._buildAst(obj[key]));
    }
    return ast;
  }
github koajs / koa-github / index.js View on Github external
module.exports = function (options) {
  options = options || {};
  if (!options.clientID || !options.clientSecret || !options.callbackURL) {
    throw new Error('github auth need clientID, clientSecret and callbackURL');
  }
  for (var key in defaultOptions) {
    if (!utility.has(options, key)) {
      options[key] = defaultOptions[key];
    }
  }
  options.callbackURL = options.callbackURL;
  options.callbackPath = urlParse(options.callbackURL).path;

  urllib.TIMEOUT = options.timeout;
  debug('init github auth middleware with options %j', options);

  return function *githubAuth(next) {
    if (!this.session) {
      return this.throw('github auth need session', 500);
    }

    // first step: redirect to github
    if (this.path === options.signinPath) {
github sofastack / sofa-bolt-node / lib / utils.js View on Github external
exports.getJavaClassname = val => {
  if (is.nullOrUndefined(val) || is.NaN(val)) {
    return DEFAULT_CLASSNAME.null;
  }

  if (val.$class) {
    const type = has(val, '$abstractClass') ? val.$abstractClass : val.$class;

    // 数组
    if (val.isArray) {
      const arrayDepth = val.arrayDepth || 1;
      let prefix = '';
      for (let i = 0; i < arrayDepth; i++) {
        prefix += '[';
      }
      return prefix + (arrayTypeMap[type] || ('L' + type + ';'));
    }
    if (type.startsWith('[')) {
      const len = type.length;
      let i = 0;
      for (; i < len; i++) {
        if (type[i] !== '[') break;
      }
github eggjs / egg-core / lib / utils / router.js View on Github external
url = url.replace(/:([a-zA-Z_]\w*)/g, function($0, key) {
        if (utility.has(args, key)) {
          const values = args[key];
          replacedParams.push(key);
          return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
        }
        return $0;
      });
github sofastack / sofa-hessian-node / lib / compile.js View on Github external
function compileProp(gen, info, key, classInfo, version, options) {
  const attr = Object.create(null, Object.getOwnPropertyDescriptors(classInfo[key]));
  if (has(attr, 'typeAliasIndex') && Array.isArray(info.generic)) {
    attr.type = info.generic[attr.typeAliasIndex].type;
    if (info.generic[attr.typeAliasIndex].generic) {
      attr.generic = info.generic[attr.typeAliasIndex].generic;
    }
  }
  const uniqueId = utils.normalizeUniqId(attr, version);
  const desc = Object.getOwnPropertyDescriptor(attr, 'defaultValue');
  if (!desc) {
    gen('compile(\'%s\', %j, classMap, version, %j)(obj[\'%s\'], encoder, appClassMap);', uniqueId, attr, options, key);
  } else {
    Object.defineProperty(attr, 'defaultValue', Object.assign({}, desc, { enumerable: false }));
    const dv = desc.get ? `({ ${utils.getterStringify(desc.get)} }).defaultValue` : JSON.stringify(desc.value);
    gen('compile(\'%s\', %j, classMap, version, %j)(utils.has(obj, \'%s\') ? obj[\'%s\'] : %s, encoder, appClassMap);', uniqueId, attr, options, key, key, dv);
  }
}