Publish your own NPM package

With so many other packages released, today we release a NPM package

First check the NPM source

npm get registry
# if not this address https://registry.npmjs.org need to set up website source
npm config set registry https://registry.npmjs.org
Copy the code

If you use a third-party source, please set the NPM official source: the third-party source only provides the download function

Create a module

npm init 

# package. Json content
{
  "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"
}

# to create index. Js
touch index.js

function isNumber(number) {
  number = parseFloat(number)
  return number === number && typeof number === 'number' 
}

module.exports = isNumber
Copy the code

[https://www.npmjs.com/](https://www.npmjs.com/) : The package name is not the same as the package name

Register an NPM account (skip this step if you have an account)

NPM adduser is used to register a user at npmjs.com.

npm adduser
# Username: indicates the Username
# Password: Password
# Email: Email

# login
npm login
Copy the code

Publish a package

npm publish
Copy the code

The default release tag is latest, and the module is a beta version, such as 2.1.1-beta, so you need to use the tag parameter

Installation and use

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
Copy the code

The demo address

Github.com/lanpangzhi/…

My blog and GitHub address

github.com/lanpangzhi

blog.langpz.com