当前位置:网站首页>开发属于自己的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命令
边栏推荐
- 【Mysql进阶优化篇02】索引失效的10种情况及原理
- 多御安全浏览器新版下载 | 功能优秀性能出众
- Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value
- UE4 通过重叠事件开启门
- flink读取mongodb数据源
- Summary of common methods of arrays
- Mysql's redo log detailed explanation
- [CISCN2019 South China Division]Web11
- 【背包九讲——01背包问题】
- 炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit
猜你喜欢

结构体初解

Mysql's redo log detailed explanation

多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容

【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】

Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value

UI自动化测试 App的WebView页面中,当搜索栏无搜索按钮时处理方法

Getting Started with Kubernetes Networking

Event parse tree Drain3 usage and explanation

日志导致线程Block的这些坑,你不得不防

YYGH-13-客服中心
随机推荐
Dive into how it works together by simulating Vite
Initial solution of the structure
概率论的学习和整理8: 几何分布和超几何分布
The test salary is so high?20K just graduated
Ali's local life's single-quarter revenue is 10.6 billion, Da Wenyu's revenue is 7.2 billion, and Cainiao's revenue is 12.1 billion
不看后悔,appium自动化环境完美搭建
Mysql's redo log detailed explanation
Kubernetes 网络入门
Web3.0 Dapps——通往未来金融世界的道路
36-Jenkins-Job迁移
The sword refers to Offer--find the repeated numbers in the array (three solutions)
rpc-remote procedure call demo
JeeSite新建报表
炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit
The most effective seven performance testing techniques of software testing techniques
[MRCTF2020]PYWebsite
shell脚本:for循环与while循环
mutillidae下载及安装
MySql index learning and use; (I think it is detailed enough)
Web3.0 Dapps - the road to the future financial world