0.0.7-alpha.0 • Published 2 years ago

@willtfn/utils v0.0.7-alpha.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

JavaScript 工具函数

安装

npm install @willtfn/utils

使用

import { setCookie } from "@willtfn/utils";
setCookie("userName", "willtfn");

函数说明

setCookie,设置 cookie

参数:

  • name,类型:string,需要设置的 cookie 名称。
  • value,类型:string | number,需要设置的 cookie 值。
  • days,类型:number,cookie 有效时间,默认 30 天。
import { setCookie } from "@willtfn/utils";
setCookie("userName", "willtfn");

getCookie,获取 cookie

参数:

  • name,类型:string,需要获取的 cookie 名称。
import { getCookie } from "@willtfn/utils";
const cookie = getCookie("userName"); // => willtfn

clearCookie,删除 cookie

参数:

  • name,类型:string,需要删除的 cookie 名称。
import { clearCookie } from "@willtfn/utils";
clearCookie("userName");

getDataType,判断数据类型

参数:

  • value,类型:any,需要判断的目标。
  • type,类型:undefined | null | number | string | boolean | object | array

该函数共两个参数,第二个参数type可选。不传入type参数时,输出字符串类型的值类型标识;传入type时,输出布尔类型的判断结果。

import { getDataType } from "@willtfn/utils";

// 判断数据类型
const dataType = getDataType(20); // => "number"

const isNumber = getDataType(20, "number"); // => true
0.0.7-alpha.0

2 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.4-alpha.0

3 years ago

0.0.3-alpha.0

3 years ago