当前位置:网站首页>开发属于自己的node包
开发属于自己的node包
2022-08-05 03:59:00 【差不少】
开发属于自己的包


转译html字符功能的包:
htmlEscape(自定义方法 暴露出来 然后require引入,下方有具体定义该转义html方法的过程)
还原html特殊字符的功能
htmlUnEscape(自定义方法 暴露出来 然后require引入,下方有具体定义该转义html方法的过程)
注:
需要自定义一个具有 格式化时间,转译html特殊字符(htmlEscape) 及 还原html特殊字符(htmlUnEscape) 这3个功能的 自定义包(自定义模块)
初始化包的基本结构

初始化package.json
注:
包的名称是唯一的,不能重复,是package.json文件中的name属性来决定的(并不是项目文件夹的名称等)
注:
所以要命名包的时候,最好先去npmjs官网上搜索一下
注:
上方node中提到的node官网皆为npmjs官网(npmjs.com),写错了
main:入口文件descriprion:描述信息license:开元许可协议,默认ISCkeywords:数组,数组中为搜索关键字
在index.js中定义 格式化时间 的方法
dateFormat

或者
date.format
// Node.js program to demonstrate the
// Date.format() method
// Importing module
const date = require('date-and-time')
// Creating object of current date and time
// by using Date()
const now = new Date();
// Formating the date and time
// by using date.format() method
const value = date.format(now,'YYYY/MM/DD HH:mm:ss');
// Display the result
console.log("current date and time:" + value)
使用以下命令运行index.js文件:
node index.js
输出:
current date and time:2021/03/07 12:13:46
在index.js中定义转义html的方法

在index.js中定义还原html方法


将不同的功能进行模块化拆分


编写包的说明文档
6项内容
书写格式:
发布包
1.注册npm账号
2.登陆npm账号
注:
这里指的登陆不是npm网站上的登陆,而是终端运行npm login命令
注:
运行npm login命令时,下包服务器的地址一定要切换为npm官方地址,否则会导致发布包失败
建议可以先使用nrm ls命令查看当前服务器地址
星号*代表当前服务器地址
把包发布到npm上
包使用 cd 文件夹名 切换到包根目录
再运行npm publish命令
边栏推荐
- Dameng 8 database export and import
- 多御安全浏览器新版下载 | 功能优秀性能出众
- Redis key basic commands
- mutillidae下载及安装
- Web3.0 Dapps - the road to the future financial world
- Slapped in the face: there are so many testers in a certain department of byte
- What is the difference between SAP ERP and ORACLE ERP?
- UE4 通过重叠事件开启门
- MySql index learning and use; (I think it is detailed enough)
- You may use special comments to disable some warnings. 报错解决的三种方式
猜你喜欢
![[Software testing] unittest framework for automated testing](/img/80/caedd5cf6dd61c9d75475866613cac.png)
[Software testing] unittest framework for automated testing
![[MRCTF2020]Ezpop(详解)](/img/19/920877ca36d1eda8d118637388ab05.png)
[MRCTF2020]Ezpop(详解)

flink读取mongodb数据源
![[极客大挑战 2019]FinalSQL](/img/e4/0c8225ef7c5e7e5bdbaac2ef6fc867.png)
[极客大挑战 2019]FinalSQL

商业智能BI业务分析思维:现金流量风控分析(一)营运资金风险

程序开发的一些常规套路(一)

Web3.0 Dapps - the road to the future financial world

【8.4】代码源 - 【数学】【历法】【删库】【不朴素的数列(Bonus)】

概率论的学习和整理8: 几何分布和超几何分布

What is the function of industrial-grade remote wireless transmission device?
随机推荐
Swing有几种常用的事件处理方式?如何监听事件?
Use CH341A to program external Flash (W25Q16JV)
Getting Started with Kubernetes Networking
iMedicalLIS listener (2)
测试薪资这么高?刚毕业就20K
bytebuffer 内部结构
Mysql's redo log detailed explanation
10 years of testing experience, worthless in the face of the biological age of 35
iMedicalLIS监听程序(2)
Redis1: Introduction to Redis, basic features of Redis, relational database, non-relational database, database development stage
【背包九讲——01背包问题】
bytebuffer internal structure
UE4 为子弹蓝图添加声音和粒子效果
token、jwt、oauth2、session解析
【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】
数组常用方法总结
Ice Scorpion V4.0 attack, security dog products can be fully detected
Bosses, I noticed that a mysql CDC connector parameters scan. The incremental. Sna
burp安装及代理设置
【Mysql进阶优化篇02】索引失效的10种情况及原理