当前位置:网站首页>从0开发一个自己的npm包
从0开发一个自己的npm包
2022-07-28 11:10:00 【卷王出征】
之前写过一些npm包,但是每次都会忘记具体流程,今天做个简单记录。
一、注册npm账号
https://www.npmjs.com
二、开发自己的npm包
1. 初始化npm包
npm init
生成package.json文件
{
"name": "create-random-value",
"version": "1.0.0",
"description": "通过传参生成指定长度的随机字符串",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"random",
"string",
"node",
"vue"
],
"author": "fujinting",
"license": "ISC"
}
2. 开发npm包
"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;
这是一个根据传入的参数,生成随机字符串的插件,使用文档下篇文章会给出,大家也可以下载使用下。
三、 上传npm包
如果你是第一次开发npm包,需要 npm adduser
当然我不是,所以我只需要 npm login 就可以了
输入 username,password ,email,这时候保证自己的npm源(镜像)是npm官方自己的 https://registry.npmjs.org/,不是请 切换 哦,否则报错提示。
接下来使用命令发布这个包
npm publish
四、检查看看


success!
边栏推荐
- R language - some metrics for unbalanced data sets
- AlexNet—论文分析及复现
- 小水滴2.0网站导航网模板
- 我想请教下各位大佬,cdc采集mysql时,如果发生了主从切换,有什么方案可以处理吗
- CVPR2021 行人重识别/Person Re-identification 论文+开源代码汇总
- Excel shortcut keys (letters + numbers) Encyclopedia
- Five Ali technical experts have been offered. How many interview questions can you answer
- ZBrush 2022 software installation package download and installation tutorial
- A hundred flowers bloom in data analysis engines. Why invest heavily in Clickhouse?
- R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the add parameter, add violin graph to the dot plot, and add the vertical line of mean standar
猜你喜欢
![[applet] how to notify users of wechat applet version update?](/img/04/848a3d2932e0dc73adb6683c4dca7a.png)
[applet] how to notify users of wechat applet version update?

中国业务型CDP白皮书 | 爱分析报告

使用 Terraform 在 AWS 上快速部署 MQTT 集群

Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects

Introduction to web security RADIUS protocol application

Byte side: how to realize reliable transmission with UDP?

Jupiter、spyder、Anaconda Prompt 、navigator 快捷键消失的解决办法

How to effectively implement a rapid and reasonable safety evacuation system in hospitals

什么样的知识付费系统功能,更有利于平台与讲师发展?

CVPR2021 行人重识别/Person Re-identification 论文+开源代码汇总
随机推荐
【补题日记】[2022牛客暑期多校2]L-Link with Level Editor I
AlexNet—论文分析及复现
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the add parameter, add violin graph to the dot plot, and add the vertical line of mean standar
Six papers that must be seen in the field of target detection
拥抱开源指南
[极客大挑战 2019]BabySQL-1|SQL注入
Iterative method for determinant (linear algebraic formula)
Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
Google Earth engine - use geetool to download single scene images in batches and retrieve NDSI results with Landsat 8
Who's the big God help? Let's see how Oracle number type parsing works. Struct{scale=15, Val
Installing sqlmap on win10 (Windows 7)
Database advanced learning notes -- object type
Learning notes tree array
Google Earth Engine——使用geetool批量下载单景影像以Landsat 8 反演后的NDSI结果
ZBrush 2022 software installation package download and installation tutorial
What is the process of switching c read / write files from user mode to kernel mode?
PKG packaging node project
[极客大挑战 2019]BabySQL-1|SQL注入
可视化大型时间序列的技巧。