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

simplepivot

v3.0.0

Published

数据透视

Readme

simplePivot

数据透视

不进行数据的汇总计算

Install

npm install --save simplepivot

Usage

declare function simplePivot(
	data: PData,
	options?: PivotOptions
): {
	columns: string[];
	list: any[][];
};

types

interface PData {
	columns: Array<string>;
	list: any[][];
	[x: string]: any;
}

interface PivotOptions {
	columns: Array<string>;
	values: string[];
	delimiter?: string;
}

Options

columns

透视列

import { simplePivot, E_VALUE } from "simplepivot";

simplePivot(data, {
    ...
	columns: ["道具名称", E_VALUE, "道具类型"],
});

注:常量E_VALUE的值为%E_VALUE%,data.columns 中避免出现%E_VALUE%,否则将出现不可预测问题。

values

透视值

delimiter

默认: _ 表头分隔符

使用


import { simplePivot, E_VALUE } from "simplepivot";

const dataset = {
    columns: ['性别', '人数'],
    list: [
        ['男', '1584'],
        ['女', '1514'],
    ]
};

const pivotData = simplePivot(dataset, {
    columns: ['性别'],
    values: ['人数']
});

console.log(pivotData);

const dataset1 = {
    columns: ['日期', '类型', '数值'],
    list: [
        ['20170809', 'A', 1],
        ['20170809', 'B', 2],
        ['20170808', 'A', 3],
        ['20170808', 'B', 4],
        ['20170808', 'C', 5],
        ['20170807', 'A', 6],
        ['20170807', 'B', 7],
    ]
};

console.log('====================')

const pivotData1 = simplePivot(dataset1, {
    columns: ['类型'],
    values: ['数值']
});

console.log(pivotData1);

其他

/**
 * 数据透视效果
 * ============================================================================================
 * metadata
 *		columns
 *		 		[日期, 游戏, 渠道, 注册数, 付费数]
 *		list
 *			[
 *				//20170809
 * 				['20170809', '游戏A', '小米', 100, 100],
 *				['20170809', '游戏A', '华为', 100, 100],
 *				['20170809', '游戏B', '华为', 100, 100],
 *				//20170808
 *				['20170808', '游戏A', '华为', 100, 100],
 *				['20170808', '游戏B', '小米', 100, 100],
 *				['20170808', '游戏B', '华为', 100, 100],
 *				//20170807
 *				['20170807', '游戏A', '小米', 100, 100],
 *			]
 *		一,透视参数:
 *			行: 日期, 渠道
 *          列: 游戏
 *          值: 注册数, 付费数
 *
 * 		效果
 *			日期      渠道   游戏A_注册数  游戏A_付费数 	游戏B_注册数    游戏B_付费数
 * 			-----------------------------------------------------------------------------------
 *			20170809   小米   100             100
 *			-----------------------------------------------------------------------------------
 *			20170809   华为    100			   100              100	              100
 *			-----------------------------------------------------------------------------------
 *			20170808   华为    100			   100              100	              100
 *			-----------------------------------------------------------------------------------
 *			20170808   小米   			                        100	              100
 *			-----------------------------------------------------------------------------------
 *			20170807   小米   100			   100
 *			-----------------------------------------------------------------------------------
 *
  *		二,透视参数:
 *			行: 日期
 *          列: 游戏, 渠道
 *          值: 注册数, 付费数
 *
 * 		效果
 *			日期      游戏A_小米_注册数  游戏A_小米_付费数  游戏A_华为_注册数  游戏A_华为_付费数  游戏B_小米_注册数  游戏B_小米_付费数  游戏B_华为_注册数  华为B_小米_付费数
 * 			---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 *			20170809   100                   100                  100                  100                                                            100                  100
 *			---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 *			20170808                                              100                  100                  100                   100                 100                  100
 *			---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 *			20170807   100			         100
 *			---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 *
 * ============================================================================================
 *
 */