npm 包 @beisen-platform/platform-runtime-helpers 使用教程

阅读时长 5 分钟读完

前言

前端开发离不开 npm 包,它们大大增强了我们的开发效率。在这篇文章中,我们将介绍 @beisen-platform/platform-runtime-helpers 这个 npm 包的使用方法。

什么是 @beisen-platform/platform-runtime-helpers

@beisen-platform/platform-runtime-helpers 是针对北森平台前端开发需求开发的运行时工具包,其中提供了许多工具函数,如日期格式化、字符串操作、Cookie 操作等。

安装

安装 @beisen-platform/platform-runtime-helpers:

使用方法

引入

在代码中引入 @beisen-platform/platform-runtime-helpers:

API

dateFormat(date, format)

参数

  • date: Date 类型或者可被转换为 Date 类型的字符串或数字。
  • format: 字符串类型,格式化字符串,如 'yyyy-MM-dd HH:mm:ss'

返回值

返回字符串型日期,如 2021-07-01 10:15:30

示例

cookie.set(name, value, expires, domain, path)

参数

  • name: 字符串型 name。
  • value: 字符串型 value。
  • expires: 可选参数,字符串型格式为 Thu, 31 Dec 2099 23:59:59 GMT
  • domain: 可选参数,字符串型。
  • path: 可选参数,字符串型。

描述

  • set 方法用于设置 Cookie。

示例

cookie.get(name)

参数

  • name: 字符串型 name。

返回值

返回字符串型 value。

描述

  • get 方法用于获取 Cookie 值。

示例

cookie.del(name, domain, path)

参数

  • name: 字符串型 name。
  • domain: 可选参数,字符串型。
  • path: 可选参数,字符串型。

描述

  • del 方法用于删除 Cookie。

示例

cookie.clear()

描述

  • clear 方法用于清空所有 Cookie。

示例

示例

-- -------------------- ---- -------
------ - ----------- ------ - ---- --------------------------------------------

----- ---- - --- -------
----- ------ - ----------- ----------
----- --- - ---------------- --------
----------------- -- ----- ---------- --------

----- ---- - -------
----- ----- - --------
----- ------- - --- -- -------
----- ------ - ------------------
----- ---- - ----
---------------- ------ -------- ------- ------
----- ----------- - -----------------
------------------------- -- ----- -----

---------------- ------- ------

---------------

总结

通过本教程我们了解了 @beisen-platform/platform-runtime-helpers 的用法,学习了其提供的 API,以及如何引入和使用该 npm 包。与其他 npm 包相比,它包含了许多工具函数,可以简化我们的工作流程,使得开发效率更高。如果您正在进行北森平台前端开发,那么这个 npm 包一定不容错过。

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/beisen-platform-platform-runtime-helpers