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

mksign

v2.0.1

Published

A lib project with ziu

Downloads

25

Readme

mksign


author: bugszhou | Email:[email protected] description: A lib project with ziu

提供对API请求参数生成签名的基础库

Usage

npm install -S mksign

使用默认的签名方式

import { defaultSign } from 'mksign';

// 需要签名的数据
const secret = 'mock_secret';
const data = {
    param1: 'test',
    name: 'tom',
    sex: ''
};

const sign = defaultSign(data, [secret]);
  • 默认签名机制:
  1. 对参加签名的参数datakey值的ASCII码从小到大排序(字典排序),将指定的key值(即v1=value1&v2=value2&v3=value3)拼接成字符串stringA;
  2. 在 stringA 最后拼接上secret得到待签名字符串stringB,并对stringB进行sha256运算,得到sign值。
  1. 值为null/undefined/''的参数会直接忽略,不参与签名。

API

defaultGetSignData(data:object, lastData: array[string, object])

对参加签名的参数datakey值的ASCII码从小到大排序(字典排序),将指定的key值(即v1=value1&v2=value2&v3=value3)拼接成字符串stringA;在 stringA 最后拼接上lastData得到待签名字符串stringB

defaultSign(data:object, lastData: array[string, object])

内部使用defaultGetSignData得到待签名字符串stringB,使用sha256stringB运算得到签名值

getFilterData(data:object)

去除datanull/undefined/''的字段,并返回排序后的字段数组

let filterData = getFilterData({
    v1: 1,
    v2: '',
    v3: null
});

console.log(filterData); // ['v1']

sort(data:object)

对参数datakey值的ASCII码从小到大排序(字典排序),返回一个key数组

filterNull(data:object)

去除datanull/undefined/''的字段, 返回新的数据

let filterData = filterNull({
    v1: 1,
    v2: '',
    v3: null
});
console.log(filterData); // {v1: 1}

getSignStr(data:array)

获取待签名字符串,data为key-value组成的二维数组;如果没有二维数组中的元素的数组长度为1,将拼接在字符串最后

let signDataStr = getSignStr([['test'], ['v1', 1], ['v5', '2']]);

console.log(signDataStr); // v1=1&v5=2test