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 🙏

© 2024 – Pkg Stats / Ryan Hefner

soei

v1.0.9

Published

工具类

Downloads

5

Readme

工具类

线上示例


Time

日期对象 获取 与 实例化

/* 时间格式化输出 */
const stringmodule =
  "YYYY-MM-DD (子|丑|丑|寅|寅|卯|卯|辰|辰|巳|巳|午|午|未|未|申|申|酉|酉|戌|戌|亥|亥|子)时 24h:mm:ss";
const soei = require("soei");
let Time = soei.Time;
// 或
const { Time } = require("soei");
// 或
import { Time } from "soei";

let t = new Time(stringmodule);
var source = new Time("今年是YY年,从MM月开始,从DD日起,下午hh:mm下班");
source.fire();
// 今年是24年,从01月开始,从13日起,下午10:17下班

source.date("今年是2024年,从05月开始,从11日起,下午16:10下班");
// Date对象: 2024-05-11T08:10:00.000Z => 标准时间 +8区

source.fire();
// 今年是24年,从05月开始,从11日起,下午16:10下班

var change = new Time("YYYY年-[DD](MM)hh*mm*ss分");
change.fire(
  /* 返回一个Date对象, 该对象 */
  source.date(
    /* 返回指定数据模版 */
    source.fire(/* '2012-01-09' */)
  )
);
// 2024年-[11](05)16*10*00分

/* date对象做参数 */
change.fire(new Date());
// 2024年-[14](01)11*18*27分

/* 标准时间转本地时间, Date本身就支持 */
change.fire("2024-05-11T08:10:00.000Z");
// 2024年-[11](05)16*10*00分
/* 版本 */
/* 版本1.0.8支持 */
// 1. 修复 dates()获取日期JSON问题
// 2. 新增 day方法

"当前日期::", t.day();
// 当前日期:: 2023-12-18 子时 23:13:14

t.day(-1, true);
// { year: 2023, month: 12, day: 17 }

t.day(-1, true);
// { year: 2023, month: 12, day: 16 }

t.day(-1, true);
// { year: 2023, month: 12, day: 15 }

t.day(-1, true);
// { year: 2023, month: 12, day: 14 }

t.day(-1);
// 2023-12-13 子时 23:13:14

t.day(-1);
// 2023-12-12 子时 23:13:14

t.day(-1);
// 2023-12-11 子时 23:13:14

t.day(-1);
// 2023-12-10 子时 23:13:14

/**
 * - 支持 days 当前月多少天
 * - 支持 week 当前天星期几
 *   index 和 weeks 只能存在一个
 **/
let week = new Time("YYYY {week} (week) -week- 本月days天「week」", {
  weeks: "星期一,星期二,星期三,星期四,星期五,星期六,星期日",
  // index: 1/* 0中文(默认)1英文 2日文 3韩文 */
});

week.fire();
// 2023 {星期四} (星期四) -星期四- 本月30天「星期四」

// 时间格式化输出
/**
 * stringmodule配置说明
 * YYYY 年
 * MM  月
 * DD   日
 * hh mm ss
 * MM|hh|DD|mm|ss|YYYY|YY|ampm|24h|12h
 * (..|..|..)
 * 24小时平分
 **/
t = new Time(stringmodule);

getDayNumberByMonthAndYear

获取当前月天数

Time.getDayNumberByMonthAndYear(1, 2022);

// 31

fire

格式化输出

t.fire(+new Date());
// 输出: "2023-09-01 申时 15:33:55"

// 或
t.fire("2088-8-8 8:8:8");
// 或
t.fire("2088/8/8 8:8:8");
// 2088-08-08 辰时 08:08:08

dates

获取当前月的详情

// 当前月
t.dates(0);

// { year: 2023, month: 9, day: 1 }

// 下一月
t.dates(1);

// { year: 2023, month: 10, day: 1 }

// 上一月
t.dates(-1);

// { year: 2023, month: 8, day: 1 }

days

获取 当前月相邻月 补位的天数集合

/**
 * 周一显示的的索引[周一的偏移量] 如果是 1 周日在第一位, 2,3,..同理
 * @param {Number} offsetByMonday
 * [
 * |一 | 二 | 三 | 四 | 五 | 六 | 日|           - 0 中文
 * ------------------------------
 * |Mon | Tue | Wed | Thu | Fri | Sat | Sun| - 1 英文
 * ------------------------------
 * |月 | 火 | 水 | 木 | 金 | 土 | 日|          - 2 日文
 * ]
 * ---------------------
 * @param {Number} title
 * 设置指定的年月日
 * {
 *     year: 2022,
 *     month: '10',
 *    day: '9'
 * }
 * @param {JSON} time
 * time未指定: 返回当前月且对应数据 cur == true
 * 指定日期: 返回指定月份
 * @returns
 **/
t.days(offsetByMonday, title, time);

// 获取当前月
t.days(0, 1);

// 获取指定月份的日期集合
t.days(0, 0, {
  year: 2023,
  month: "10",
  /* 指定选中日期 */
  day: "9",
});
/*
[
  { day: '一', title: 'title' },
  { day: '二', title: 'title' },
  { day: '三', title: 'title' },
  { day: '四', title: 'title' },
  { day: '五', title: 'title' },
  { day: '六', title: 'title' },
  { day: '日', title: 'title' },
  { day: 25, month: 9, year: 2023, title: 'prev' },
  ...
  { day: 30, month: 9, year: 2023, title: 'prev' },
  { day: 1, month: 10, year: 2023, title: 'current', cur: false },
  ...
  { day: 9, month: 10, year: 2023, title: 'current', cur: true },
  ...
  { day: 31, month: 10, year: 2023, title: 'current', cur: false },
  { day: 1, month: 11, year: 2023, title: 'next' },
  ...
  { day: 5, month: 11, year: 2023, title: 'next' }
]
*/

date

返回指定日期的对象

t.date("2022-10-20 10:20:30");

// 2022-10-20T02:20:30.000Z
// 这个是对象输出调用toString()后的结果

Between

// 区间取值
const soei = require("soei");
let Between = soei.Between;
// 或
import { Between } from "soei";

data = new Between({
  /* 是否含有小数输出, 默认为0, 整数 */
  // decimal: 3,
  max: 90,
  min: 20,
});
data.fire(20.01);
// 20
data.fire(2);
// 20
data.fire(2, true /* 是否正在输入, 当为true时不直接返回最大最小值 */);
// 2
data = new Between({
  decimal: 3,
  max: 1,
  min: 0,
});

data.fire(20);
// 1.000
data.fire("0.0");
// 0.000
data.fire("0.0", true);
// 0.0
data.fire(0.0, true);
// 0

merge

// 合并
const soei = require("soei");
let merge = soei.merge;
// 或
import { merge } from "soei";

// 合并
merge(args1, args2[,..., true, "mix"])

// ### 用法一

// 基本用法
merge(args1, args2)

let a = { name: "Joy" };
let b = { name: "Band", age: 10 };
merge(a, b);
// a : {name: 'Joy', age: 10}
// b : {name: 'Band', age: 10}

// ### 用法二

// 强制覆盖
merge(args1, args2, args3, true)

// - args1, args2 为接收方
// - args3 为属性输出方

let a = { name: "Joy" };
let b = { name: "Band", age: 10 };
let c = { name: "Juerry" };
// 这里以 c 为模版, 把 c 中的属性强制覆盖到 前面的一个或者多个对象中去
merge(a, b, c, true);
// a, b为接收方
// a : {name: 'Juerry'}
// b : {name: 'Juerry', age: 10}
// c : {name: 'Juerry'}

// ### 用法三

//  多参数
merge(args1, args2, args3)

//  - args1, args2 为接收方
//  - args3 为属性输出方

let a = { name: "Joy" };
let b = { name: "Band", age: 10 };
merge(a, b, {
  age: 11,
});
// a, b为接收方
// a : {name: 'Joy', age: 11}
// b : {name: 'Band', age: 10}

// ### 用法四

// 末尾参数为 "mix" 时, args1 为接收方, 其他参数均为属性输出方
merge(args1, args2[,...], "mix")

let a = { name: "Joy" };
let b = { name: "Band" };
let c = { name: "Juerry", age: 10 };
// 参数1, 参数2
merge(a, b, c, "mix");
// a为接收方 b, c为属性输出方
// a: { name: 'Joy', age: 10 }
// b: { name: 'Band' }
// c: { name: "Juerry", age: 10 }

// ### 用法五

merge(args1, args2[,...], true, "mix")
//  true 和 mix 的混合使用
//  最终属性值取决于最后一次出现的属性

let a = { name: "Joy" };
let b = { name: "Band" };
let c = { name: "Juerry", age: 11 };
merge(a, b, c, true, "mix");
// a为接收方 b, c为属性输出方
// a: {name: 'Juerry', age: 11}
// b: {name: 'Band'}
// c: {name: 'Juerry', age: 11}

each

const soei = require("soei");
let each = soei.each;
// 或
import { each } from "soei";

each({ a: 1, b: 2 }, (k, v) => {
  console.log(k, v);
});
// 输出:
// a 1
// b 2
each([1, 2], (k, v) => {
  // 如果打开注释, 如条件满足,则不再输出,直接跳出循环
  // if(v >= 1) return true;
  console.log(k, v);
});
// 输出:
// 0 1
// 1 2

/**
 * 这里的 ...对应handle(key, item, ...)
 * each(source, handle [, ...])
 * each({}, (key, item, v1, v2, v3) => {
 *  v1 == 1
 *  v2 == 2
 *  v3 == 3
 * }, 1, 2, 3)
 */
each(
  [1, 2],
  (k, v, target /* each的第三个参数, 以此类推... */) => {
    console.log(target);
    /* 输出: 
  {
    1: 2,
    2: 3
  }
  */
  },
  {
    1: 2,
    2: 3,
  }
);

runer

const soei = require("soei");
let runer = soei.runer;
// 或
import { runer } from "soei";

runer(
  function (a, z) {
    return `this is ${this.name} ${a} ${z}`;
  },
  {
    name: "loop",
  },
  1,
  2
);
// 输出: this is loop 1 2

iList2Array

const soei = require("soei");
let iList2Array = soei.iList2Array;
// 或
import { iList2Array } from "soei";

// 转换数组
let array = iList2Array(arguments);

iSplit

const soei = require("soei");
let iSplit = soei.iSplit;
// 或
import { iSplit } from "soei";

// 转换数组
let array = iSplit("name|age;weight");
// ['name', 'age', 'weight']
let array = iSplit("name,age", ",");
// ['name', 'age']

picker

const { picker } = require("soei");

// 或

import { picker } from "soei";

let data;
/* :: 用法一 */

// 别名输出
picker(
  {
    a: {
      b: {
        c: "d",
      },
    },
  },
  "a.b.c=>abc,e"
);

// 输出 {abc: 'd'} data.e = undefined 不包含e
/* :: 用法二 */

// 模糊输出 *=>*
picker(
  {
    a: {
      b: {
        c: "d",
        e: "e",
      },
    },
  },
  "a.b.*=>*"
);

// 输出 {c: 'd', e: 'e'}
/* :: 用法三 */

// 多查询"|", 优先级和顺序相关[1|2|3]
picker(
  {
    a: {
      b: {
        c: "d",
        e: "e",
      },
    },
    c: 3,
  },
  "a.b.c|c=>c"
);
// 输出 {c: 'd'}
/* :: 用法四 */

data = [{ n: "d" }, { n: "i" }, { n: "v" }];

picker(data, "n=>name,n=>value");

/* 
输出 
[
  { name: 'd', value: 'd' },
  { name: 'i', value: 'i' },
  { name: 'v', value: 'v' }
]
*/
/* :: 用法五 */

// node上下文, arguments 对应 node运行时的传参
data = arguments;

// 获取第三个元素的path属性赋值给name输出 获取到当前目录
picker(data, "2.path=>name");

// 输出 { name: '/Users/soei/Storage/npm/@soei/picker' }

isFunction

isNil

isSimplyType

isArray

isString

isNodeList