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 🙏

© 2025 – Pkg Stats / Ryan Hefner

seiminutils

v1.0.5

Published

实用工具方法

Readme

安装

浏览器环境

<script src="./node_modules/seiminutils/lib/seiminutils.js"></script>

通过 npm

npm install seiminutils

使用

// esm(全部导入)
import seiminutils from "seiminutils";
// esm(按需导入)
import dateFormat from "seiminutils/es/dateFormat.js"; //格式化日期
import multisort from "seiminutils/es/multisort.js"; //对象数组排序
// cjs
const seiminutils = require("seiminutils");

基础

getDataType - 获取数据类型

seiminutils.getDataType();
// => undefined
seiminutils.getDataType(null);
// => null
seiminutils.getDataType([]);
// => array

日期

dateFormat - 格式化日期

seiminutils.dateFormat();
// => 当前日期
seiminutils.dateFormat(1662280786269, "yyyy-MM-dd hh:mm:ss");
// => 2022-09-04 16:39:46
seiminutils.dateFormat(1662280786269, "yyyy-MM-dd");
// => 2022-09-04

数组

multisort - 对象数组排序

const data = [
  { name: "张三", age: 29, grade: 90 },
  { name: "李四", age: 28, grade: 90 },
  { name: "王五", age: 27, grade: 100 },
];
seiminutils.multisort(
  data,
  (a, b) => a.grade - b.grade,
  (a, b) => a.age - b.age
);
// 先按分数递增,再按年龄递增
// [
//   { name: '李四', age: 28, grade: 90 },
//   { name: '张三', age: 29, grade: 90 },
//   { name: '王五', age: 27, grade: 100 }
// ]

tranListToTreeData - 扁平化结构转成树形结构

const data = [
  { id: 1, name: "司令", pid: 0 },
  { id: 2, name: "军长", pid: 1 },
  { id: 3, name: "副军长", pid: 1 },
  { id: 4, name: "师长1", pid: 2 },
  { id: 6, name: "师长2", pid: 2 },
  { id: 7, name: "师长3", pid: 3 },
  { id: 8, name: "师长4", pid: 3 },
  { id: 9, name: "师长5", pid: 3 },
];
seiminutils.tranListToTreeData(data, 0, "pid");
// 树形结构
// [
//   {
//     id: 1,
//     name: "司令",
//     pid: 0,
//     children: [
//       {
//         id: 2,
//         name: "军长",
//         pid: 1,
//         children: [
//           {
//             id: 4,
//             name: "师长1",
//             pid: 2,
//             children: [],
//           },
//           {
//             id: 6,
//             name: "师长2",
//             pid: 2,
//             children: [],
//           },
//         ],
//       },
//       {
//         id: 3,
//         name: "副军长",
//         pid: 1,
//         children: [
//           {
//             id: 7,
//             name: "师长3",
//             pid: 3,
//             children: [],
//           },
//           {
//             id: 8,
//             name: "师长4",
//             pid: 3,
//             children: [],
//           },
//           {
//             id: 9,
//             name: "师长5",
//             pid: 3,
//             children: [],
//           },
//         ],
//       },
//     ],
//   },
// ]

tranTreeToListData - 树形结构转扁平化结构

const data = [
  {
    id: 1,
    name: "司令",
    pid: 0,
    children: [
      {
        id: 2,
        name: "军长",
        pid: 1,
        children: [
          {
            id: 4,
            name: "师长1",
            pid: 2,
            children: [],
          },
          {
            id: 6,
            name: "师长2",
            pid: 2,
            children: [],
          },
        ],
      },
      {
        id: 3,
        name: "副军长",
        pid: 1,
        children: [
          {
            id: 7,
            name: "师长3",
            pid: 3,
            children: [],
          },
          {
            id: 8,
            name: "师长4",
            pid: 3,
            children: [],
          },
          {
            id: 9,
            name: "师长5",
            pid: 3,
            children: [],
          },
        ],
      },
    ],
  },
];
seiminutils.tranTreeToListData(data, 0, "pid");
// 扁平化结构
// [
//   { id: 1, name: "司令", pid: 0 },
//   { id: 2, name: "军长", pid: 1 },
//   { id: 3, name: "副军长", pid: 1 },
//   { id: 4, name: "师长1", pid: 2 },
//   { id: 6, name: "师长2", pid: 2 },
//   { id: 7, name: "师长3", pid: 3 },
//   { id: 8, name: "师长4", pid: 3 },
//   { id: 9, name: "师长5", pid: 3 },
// ]