当前位置:网站首页>开发属于自己的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
命令
边栏推荐
- Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
- 2022 Hangzhou Electric Multi-School 1st Game
- bytebuffer 内部结构
- 36-Jenkins-Job迁移
- Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
- mutillidae下载及安装
- Redis1: Introduction to Redis, basic features of Redis, relational database, non-relational database, database development stage
- Redis1:Redis介绍、Redis基本特性、关系型数据库、非关系型数据库、数据库发展阶段
- Spark Basics [Introduction, Getting Started with WordCount Cases]
- Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value
猜你喜欢
UE4 opens door via interaction (keyboard key)
Hard power or soft power, which is more important to testers?
In the WebView page of the UI automation test App, the processing method when the search bar has no search button
【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】
从企业的视角来看,数据中台到底意味着什么?
Android 面试题——如何徒手写一个非阻塞线程安全队列 ConcurrentLinkedQueue?
UE4 通过与其它Actor互动开门
iMedicalLIS监听程序(2)
4T硬盘剩余很多提示“No space left on device“磁盘空间不足
Paparazzi: Surface Editing by way of Multi-View Image Processing
随机推荐
Shell script: for loop and the while loop
UE4 第一人称角色模板 添加生命值和调试伤害
36-Jenkins-Job Migration
UE4 为子弹蓝图添加声音和粒子效果
[MRCTF2020]Ezpop(详解)
The test salary is so high?20K just graduated
Ice Scorpion V4.0 attack, security dog products can be fully detected
iMedicalLIS监听程序(2)
GC Gaode coordinate and Baidu coordinate conversion
测试薪资这么高?刚毕业就20K
Redis key basic commands
Use Unity to publish APP to Hololens2 without pit tutorial
In the WebView page of the UI automation test App, the processing method when the search bar has no search button
36-Jenkins-Job迁移
工业级远距离无线传输装置的功能有哪些?
SkiaSharp 之 WPF 自绘 粒子花园(案例版)
[GYCTF2020]EasyThinking
Swing有几种常用的事件处理方式?如何监听事件?
队列题目:最近的请求次数
四位数显表头设计