用了这么屡次别人发布的包,今天我们本身发布一个npm包html
npm get registry # 若是不是这个地址https://registry.npmjs.org 须要设置官网源 npm config set registry https://registry.npmjs.org
若是是使用第三方源请设置npm官方源 (注):第三方源只提供下载功能
git
npm init # package.json 内容 { "name": "isnumber-lpz", "version": "1.0.0", "description": "Number\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[C\u001b[C\u001b[Cis\u001b[C\u001b[C\u001b[Number", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/lanpangzhi/isNumber-lpz.git" }, "author": "lanpangzhi", "license": "ISC", "bugs": { "url": "https://github.com/lanpangzhi/isNumber-lpz/issues" }, "homepage": "https://github.com/lanpangzhi/isNumber-lpz#readme" } # 建立 index.js touch index.js function isNumber(number) { number = parseFloat(number) return number === number && typeof number === 'number' } module.exports = isNumber
npm使用介绍里面有里面的字段,这里就省略了,(注):包的name不要重名建议先去[https://www.npmjs.com/](https://www.npmjs.com/)搜索下
github
npm adduser用于在npmjs.com注册一个用户。npm
npm adduser # Username: 用户名 # Password: 密码 # Email: 邮箱 # 登陆 npm login
npm publish
(注):发布的时候版本号要和上次的不同,默认的发布标签是latest、前模块是一个beta版,好比2.1.1-beta,那么发布的时候须要使用tag参数
json
npm i isnumber-lpz const isNumber = require('isnumber-lpz') console.log('12', isNumber(12)) true console.log('12.2', isNumber(12.2)) true console.log('x12.2', isNumber('x12.2')) false console.log('xacsa', isNumber('xacsa')) false
## demo 地址
https://github.com/lanpangzhi/isNumber-lpzui
# 个人博客和GitHub地址
https://github.com/lanpangzhiurl