当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript underscore.has函数代码示例

本文整理汇总了TypeScript中underscore.has函数的典型用法代码示例。如果您正苦于以下问题:TypeScript has函数的具体用法?TypeScript has怎么用?TypeScript has使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了has函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: handleError

	public handleError(raw: Response | any) {
		console.error(raw);
		// If server sends 401 'Unauthorized'
		if(_.has(raw, 'status') && raw.status == 401 && raw._body == 'Unauthorized') {
			// Delete token in local storage and redirect
			window.localStorage.removeItem('currentUser');
			this.router.navigate(['/login']);
			
			return Observable.throw(raw);
		}
		
		var error = raw.json();
		
		// Show alert component if alert object is part of the server response
		var self = this;
		if(_.has(error, 'alert')) {
			// First clear old alerts
			self.alert.clear();
			
			// Push new alert
			this.translate.get(error.alert.content, error.alert.vars).subscribe(str => {
				self.alert.alert(error.alert.type, str);
			});
		}
		
		return Observable.throw(error);
	}
开发者ID:openevocracy,项目名称:openevocracy,代码行数:27,代码来源:http-manager.service.ts

示例2: processLoadout

 .then((data) => {
   if (_.has(data, 'loadouts-v3.0')) {
     return processLoadout(data, 'v3.0');
   } else {
     return [];
   }
 })
开发者ID:delphiactual,项目名称:DIM,代码行数:7,代码来源:loadout.service.ts

示例3: formatUrlParam

 /**
  * 格式化url参数
  */
 static formatUrlParam(url: string = ''): {[key: string]: string | string[]} {
   let paramObject: any = {}
   let urlParam: string[];
   url = url.replace(/^\?/, '');
   if (url && url.length > 1) {
     urlParam = url.split('&');
   } else {
     urlParam = [];
   }
   for (let item of urlParam) {
     let [key, value] = item.split('=');
     if (!key) continue;
     key = key.replace(/\[\]$/, '');
     if (value) {
       value = value.replace(/%u\w{4}/g, (char) => unescape(char));
       value = decodeURIComponent(value);
     }
     else {
       value = '';
     }
     if (_.has(paramObject, key)) {
       if (!_.isArray(paramObject[key])) {
         paramObject[key] = [paramObject[key]];
       }
       paramObject[key].push(value);
     }
     else {
       paramObject[key] = value;
     }
   }
   return paramObject;
 }
开发者ID:thinkjs,项目名称:learn-react,代码行数:35,代码来源:utilService.ts

示例4: saveLoadouts

      .then((loadouts) => {
        if (!_.has(loadout, 'id')) {
          loadout.id = uuidv4();
        }

        // Handle overwriting an old loadout
        const existingLoadoutIndex = _.findIndex(loadouts, { id: loadout.id });
        if (existingLoadoutIndex > -1) {
          loadouts[existingLoadoutIndex] = loadout;
        } else {
          loadouts.push(loadout);
        }

        return saveLoadouts(loadouts);
      })
开发者ID:delphiactual,项目名称:DIM,代码行数:15,代码来源:loadout.service.ts

示例5: isGuid

 const hasGuid = (item) => _.has(item, 'id') && isGuid(item.id);
开发者ID:delphiactual,项目名称:DIM,代码行数:1,代码来源:loadout.service.ts

示例6: hasToken

	public hasToken() {
		if(_.has(this.getUser(), 'token'))
			return true
		else
			return false
	}
开发者ID:openevocracy,项目名称:openevocracy,代码行数:6,代码来源:user.service.ts

示例7: http

export function http(method: string, url: string, options?: any, callback?: Function) {

  ////////// Process arguments //////////

  if (!callback && typeof options === "function") {
    // support (method, url, callback) argument list
    callback = options;
    options = null;
  }

  options = options || {};

  if (typeof callback !== "function")
    throw new Error(
      "Can't make a blocking HTTP call from the client; callback required.");

  method = (method || "").toUpperCase();

  const headers = {};

  let content = options.content;
  if (options.data) {
    content = JSON.stringify(options.data);
    headers['Content-Type'] = 'application/json';
  }

  let params_for_url;
  let params_for_body;

  if (content || method === "GET" || method === "HEAD") {
    params_for_url = options.params;
  } else {
    params_for_body = options.params;
  }

  url = constructUrl(url, options.query, params_for_url);

  if (options.followRedirects === false)
    throw new Error("Option followRedirects:false not supported on client.");

  if (has(options, 'npmRequestOptions')) {
    throw new Error("Option npmRequestOptions not supported on client.");
  }

  let username;
  let password;

  if (options.auth) {
    const colonLoc = options.auth.indexOf(':');
    if (colonLoc < 0)
      throw new Error('auth option should be of the form "username:password"');
    username = options.auth.substring(0, colonLoc);
    password = options.auth.substring(colonLoc + 1);
  }

  if (params_for_body) {
    content = encodeParams(params_for_body);
  }

  extend(headers, options.headers || {});

  ////////// Callback wrapping //////////

  // wrap callback to add a 'response' property on an error, in case
  // we have both (http 4xx/5xx error, which has a response payload)
  callback = (function(callback) {
    return function(error, response) {
      if (error && response)
        error.response = response;
      callback(error, response);
    };
  })(callback);

  // safety belt: only call the callback once.
  callback = once(callback);


  ////////// Kickoff! //////////

  // from this point on, errors are because of something remote, not
  // something we should check in advance. Turn exceptions into error
  // results.
  try {
    // setup XHR object
    let xhr;
    if (typeof XMLHttpRequest !== "undefined")
      xhr = new XMLHttpRequest();
    else if (typeof ActiveXObject !== "undefined")
      xhr = new ActiveXObject("Microsoft.XMLHttp"); // IE6
    else
      throw new Error("Can't create XMLHttpRequest"); // ???

    xhr.open(method, url, true, username, password);

    for (let k in headers)
      xhr.setRequestHeader(k, headers[k]);


    // setup timeout
    let timed_out = false;
//.........这里部分代码省略.........
开发者ID:apollostack,项目名称:http,代码行数:101,代码来源:http.ts

示例8: makeCharacter

export function makeCharacter(
  raw,
  defs: D1ManifestDefinitions,
  mostRecentLastPlayed: Date,
  currencies: D1Currencies
): {
  store: D1Store;
  items: any[];
} {
  const character = raw.character.base;
  try {
    currencies.glimmer = character.inventory.currencies.find(
      (cur) => cur.itemHash === 3159615086
    ).value;
    currencies.marks = character.inventory.currencies.find(
      (cur) => cur.itemHash === 2534352370
    ).value;
    currencies.silver = character.inventory.currencies.find(
      (cur) => cur.itemHash === 2749350776
    ).value;
  } catch (e) {
    console.log('error', e);
  }

  const race = defs.Race[character.characterBase.raceHash];
  let genderRace = '';
  let className = '';
  let gender = '';
  if (character.characterBase.genderType === 0) {
    gender = 'male';
    genderRace = race.raceNameMale;
    className = defs.Class[character.characterBase.classHash].classNameMale;
  } else {
    gender = 'female';
    genderRace = race.raceNameFemale;
    className = defs.Class[character.characterBase.classHash].classNameFemale;
  }

  const lastPlayed = new Date(character.characterBase.dateLastPlayed);

  const store: D1Store = Object.assign(Object.create(StoreProto), {
    destinyVersion: 1,
    id: raw.id,
    name: `${genderRace} ${className}`,
    icon: `https://www.bungie.net/${character.emblemPath}`,
    current: mostRecentLastPlayed.getTime() === lastPlayed.getTime(),
    lastPlayed,
    background: `https://www.bungie.net/${character.backgroundPath}`,
    level: character.characterLevel,
    powerLevel: character.characterBase.powerLevel,
    stats: getCharacterStatsData(defs.Stat, character.characterBase),
    class: getClass(character.characterBase.classType),
    classType: character.characterBase.classType,
    className,
    gender,
    genderRace,
    percentToNextLevel: character.percentToNextLevel / 100,
    progression: raw.character.progression,
    advisors: raw.character.advisors,
    isVault: false
  });

  if (store.progression) {
    store.progression.progressions.forEach((prog) => {
      Object.assign(
        prog,
        defs.Progression.get(prog.progressionHash),
        progressionMeta[prog.progressionHash]
      );
      const faction = _.find(defs.Faction, { progressionHash: prog.progressionHash });
      if (faction) {
        prog.faction = faction;
      }
    });
  }

  let items: any[] = [];
  _.each(raw.data.buckets, (bucket: any) => {
    _.each(bucket, (pail: any) => {
      _.each(pail.items, (item: any) => {
        item.bucket = pail.bucketHash;
      });

      items = items.concat(pail.items);
    });
  });

  if (_.has(character.inventory.buckets, 'Invisible')) {
    _.each(character.inventory.buckets.Invisible, (pail: any) => {
      _.each(pail.items, (item: any) => {
        item.bucket = pail.bucketHash;
      });

      items = items.concat(pail.items);
    });
  }

  return {
    store,
    items
//.........这里部分代码省略.........
开发者ID:bhollis,项目名称:DIM,代码行数:101,代码来源:d1-store-factory.service.ts


注:本文中的underscore.has函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。