{"action":"opened","issue":{"url":"https://api.github.com/repos/itboos/accumulation/issues/14","repository_url":"https://api.github.com/repos/itboos/accumulation","labels_url":"https://api.github.com/repos/itboos/accumulation/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/itboos/accumulation/issues/14/comments","events_url":"https://api.github.com/repos/itboos/accumulation/issues/14/events","html_url":"https://github.com/itboos/accumulation/issues/14","id":310025259,"number":14,"title":"npm ","user":{"login":"itboos","id":21290640,"avatar_url":"https://avatars1.githubusercontent.com/u/21290640?v=4","gravatar_id":"","url":"https://api.github.com/users/itboos","html_url":"https://github.com/itboos","followers_url":"https://api.github.com/users/itboos/followers","following_url":"https://api.github.com/users/itboos/following{/other_user}","gists_url":"https://api.github.com/users/itboos/gists{/gist_id}","starred_url":"https://api.github.com/users/itboos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itboos/subscriptions","organizations_url":"https://api.github.com/users/itboos/orgs","repos_url":"https://api.github.com/users/itboos/repos","events_url":"https://api.github.com/users/itboos/events{/privacy}","received_events_url":"https://api.github.com/users/itboos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-30T09:47:37Z","updated_at":"2018-03-30T09:47:37Z","closed_at":null,"author_association":"OWNER","body":"###npm 一些小的工具包的源码学习:\r\nrepeat-string\r\n (https://github.com/jonschlinkert/repeat-string)\r\n\r\n```javascript\r\n /*!\r\n * repeat-string <https://github.com/jonschlinkert/repeat-string>\r\n *\r\n * Copyright (c) 2014-2015, Jon Schlinkert.\r\n * Licensed under the MIT License.\r\n */\r\n\r\n'use strict';\r\n\r\n/**\r\n * Results cache\r\n */\r\n\r\nvar res = '';\r\nvar cache;\r\n\r\n/**\r\n * Expose `repeat`\r\n */\r\n\r\nmodule.exports = repeat;\r\n\r\n/**\r\n * Repeat the given `string` the specified `number`\r\n * of times.\r\n *\r\n * **Example:**\r\n *\r\n * ```js\r\n * var repeat = require('repeat-string');\r\n * repeat('A', 5);\r\n * //=> AAAAA\r\n * ```\r\n *\r\n * @param {String} `string` The string to repeat\r\n * @param {Number} `number` The number of times to repeat the string\r\n * @return {String} Repeated string\r\n * @api public\r\n */\r\n\r\nfunction repeat(str, num) {\r\n  if (typeof str !== 'string') {\r\n    throw new TypeError('expected a string');\r\n  }\r\n\r\n  // cover common, quick use cases\r\n  if (num === 1) return str;\r\n  if (num === 2) return str + str;\r\n\r\n  var max = str.length * num; \r\n  if (cache !== str || typeof cache === 'undefined') {\r\n    cache = str;\r\n    res = '';\r\n  } else if (res.length >= max) {\r\n    return res.substr(0, max);\r\n  }\r\n  while (max > res.length && num > 1) {\r\n    if (num & 1) { // 是奇数, 奇数与奇数 & 为奇数， 与偶数 2 & 1  = 0  位操作的目的是效率更高\r\n      res += str;\r\n    }\r\n\r\n    num >>= 1; // num / 2 ( 等于num整除2 )\r\n    str += str;\r\n  }\r\n\r\n  res += str;\r\n  res = res.substr(0, max);\r\n  return res;\r\n}\r\n\r\n```\r\n参考链接:\r\nhttps://stackoverflow.com/questions/4115045/ruby-what-does-the-snippet-num-1-0-exactly-do"}}
{"actor":{"display_login":"itboos"}}