npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codernote/utils

v1.9.1

Published

笔记软件通用工具库

Downloads

183

Readme

工具库

笔记软件通用工具库

安装

npm install @codernote/utils

公共环境变量

import { ENV, setEnv } from "@codernote/utils";

// 手动指定环境
// 不手动指定则会根据域名自动识别
setEnv("dev" | "test" | "prod");
// 可以单独直接设定env值
setEnv({
  URL_SERVER_HTTP: "http://localhost:7000",
});

console.log(ENV);
/*
ENV{
  // 当前环境
  ENV: "TEST",

  // 后端服务域名
  URL_DOMAIN,

  // 后端HTTP服务地址
  URL_SERVER_HTTP: "",

  // 后端websocket服务地址
  URL_SERVER_WSS: "",

  // media服务地址
  URL_SERVER_MEDIA: "",

  // 公共登录页面地址
  URL_PAGE_LOGIN_PC: "",

  // 公共用户信息页面地址
  URL_PAGE_USER_PC: "",
}
*/

工具函数

uuid: 生成 uuid

import { uuid } from "@codernote/utils";

const id = uuid();

parseMimeType: 解析 mimeType

import { parseMimeType } from "@codernote/utils";
const mimeType = 'video/mp4; codec="avc1.42E01E"';
const parsed = parseMimeType(mimeType);

console.log(parsed);
// 输出: { mainType: 'video', subType: 'mp4', params: ['codec="avc1.42E01E"'] }

判断设备类型

import { detectDeviceType } from "@codernote/utils";

const type = detectDeviceType();
console.log(type);
// 输出: mobile | desktop

获取 url 参数

import { getQueryParam } from "@codernote/utils";

const a = getQueryParam("a");

优化字节大小展示

import { formatBytes } from "@codernote/utils";

const a = formatBytes(1024);
console.log(a);
// 1KB

截取字符串

import { truncateString } from "@codernote/utils";

const a = truncateString("xxxxxx", 3);
console.log(a);
// xxx...

根据 File 获取图片或视频宽高

import { getVideoSize, getImageSize } from "@codernote/utils";

const { width, height } = getVideoSize(fileVideo);
// 或
const { width, height } = getImageSize(fileImage);

根据最大宽高比例,重设宽高

import { resizeResource } from "@codernote/utils";
const width = 600;
const height = 400;

// 最大限制宽300, 限高300(均为默认值)
const size = resizeResource(width, height, 300, 300);

console.log(size);
// {width: 300, height: 200}

oss

上传文件到 CDN

import { oss } from "@codernote/utils";

oss.uploadFile(files, (err, resArr) => {
  if (!err) {
    console.log(resArr);
  }
});

删除上传的文件

import { oss } from "@codernote/utils";

oss.removeFile(filePath);

事件

长按事件

import { addLongPressEventListener } from "@codernote/utils";

// 绑定domEl上,长按事件(500ms默认值)
addLongPressEventListener(domEl, callback, 1000);

icons

一组常用 icons

import { icons } from "@codernote/utils";

console.log(icons);
/*
[
  { name: "add.svg", value: base64 }
  ...
]
 */

byNameFindIcon: 根据名称找 icon

import { byNameFindIcon } from "@codernote/utils";

byNameFindIcon("clear.svg");

发布

npm publish --access public