当前位置:网站首页>Develop your own NPM package from 0
Develop your own NPM package from 0
2022-07-28 11:51:00 【The king of the scroll goes to war】
I've written a few before npm package , But every time I forget the specific process , Make a simple record today .
One 、 register npm account number
https://www.npmjs.com
Two 、 Develop your own npm package
1. initialization npm package
npm init
Generate package.json file
{
"name": "create-random-value",
"version": "1.0.0",
"description": " Generate a random string of specified length by passing parameters ",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"random",
"string",
"node",
"vue"
],
"author": "fujinting",
"license": "ISC"
}
2. Development npm package
"use strict";
const number = "123467890";
const bigLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const smallLetter = "abcdefghijklmnopqrstuvwxyz";
const punctuation = "[email protected]#$%^&*()_+-=[]{}|;:,./<>?";
function random(length, option) {
let char = "";
let result = "";
length || (length = 8);
option || (option = {});
if (option === true) {
char = number + bigLetter + smallLetter + punctuation;
} else if (typeof option == "string") {
char = option;
} else {
if (option.number !== false) {
char += typeof option.number == "string" ? option.number : number;
}
if (option.bigLetter !== false) {
char +=
typeof option.bigLetter == "string" ? option.bigLetter : bigLetter;
}
if (option.smallLetter !== false) {
char +=
typeof option.smallLetter == "string"
? option.smallLetter
: smallLetter;
}
if (option.punctuation) {
char +=
typeof option.punctuation == "string"
? option.punctuation
: punctuation;
}
}
while (length > 0) {
length--;
result += char[Math.floor(Math.random() * char.length)];
}
return result;
}
module.exports = random;
This is based on the passed in parameter , Plug in for generating random strings , Use the document. The next article will give , You can also download and use .
3、 ... and 、 Upload npm package
If you are developing for the first time npm package , need npm adduser
Of course I'm not , So I just need npm login That's all right.
Input username,password ,email, At this time, ensure your npm Source ( Mirror image ) yes npm It's official https://registry.npmjs.org/, Not please Switch Oh , Otherwise, an error message will be given .
Next, use the command to release this package
npm publish
Four 、 Check it out


success!
边栏推荐
- PFP会是数字藏品的未来吗?
- Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
- 学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
- Outlook suddenly becomes very slow and too laggy. How to solve it
- consul安装与配置
- MySQL (version 8.0.16) command and description
- Direct insert sort and Hill sort
- 我想请教下各位大佬,cdc采集mysql时,如果发生了主从切换,有什么方案可以处理吗
- Service Workers让网站动态加载Webp图片
- 【补题日记】[2022牛客暑期多校2]L-Link with Level Editor I
猜你喜欢

Cvpr2021 pedestrian re identification /person re identification paper + summary of open source code

目标检测领域必看的6篇论文

Solutions to the disappearance of Jupiter, spyder, Anaconda prompt and navigator shortcut keys

Today's sleep quality record 74 points

「以云为核,无感极速」第五代验证码重磅来袭

CVPR2020 best paper:对称可变形三维物体的无监督学习
![ASP. Net core 6 framework unveiling example demonstration [29]: building a file server](/img/90/40869d7c03f09010beb989af07e2f0.png)
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server

Byte side: how to realize reliable transmission with UDP?

Autumn recruit offer harvesters, and take the offers of major manufacturers at will

Localization, low latency, green and low carbon: Alibaba cloud officially launched Fuzhou data center
随机推荐
AlexNet—论文分析及复现
业务可视化-让你的流程图'Run'起来(4.实际业务场景测试)
15、用户web层服务(三)
Introduction to the usage of SAP ui5 image display control avatar trial version
Flutter tutorial flutter navigator 2.0 with gorouter, use go_ Router package learn about the declarative routing mechanism in fluent (tutorial includes source code)
Router firmware decryption idea
Function of interface test
Go deadlock - when the channel meets mutex
从零开始Blazor Server(2)--整合数据库
哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
什么是WordPress
Tiktok programmer confession special code tutorial (how to play Tiktok)
jar 包内文件的遍历以及文件的拷贝
zotero文献管理器及其使用姿势(不定时更新)
Redis安装
Quickly deploy mqtt clusters on AWS using terraform
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials
B2 sub theme / blog b2child sub theme / open source code
Solutions to the disappearance of Jupiter, spyder, Anaconda prompt and navigator shortcut keys