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

mock-table-data

v2.0.3

Published

`mock-table-data`는 JavaScript/TypeScript 환경에서 테이블 형태의 데이터를 조건, 정렬, 페이징 기반으로 필터링하거나 가공할 수 있는 유틸리티 클래스입니다. 테스트용 또는 실제 클라이언트 필터링 용도로 사용할 수 있습니다.

Readme

mock-table-data

mock-table-data는 JavaScript/TypeScript 환경에서 테이블 형태의 데이터를 조건, 정렬, 페이징 기반으로 필터링하거나 가공할 수 있는 유틸리티 클래스입니다. 테스트용 또는 실제 클라이언트 필터링 용도로 사용할 수 있습니다.


설치

npm install mock-table-data

또는

yarn add mock-table-data

사용법

import TableData from 'mock-table-data';

const table = new TableData(dataSource, {
  primaryKey: 'id', // 선택사항
  dataProcessing: (data) => data.map(row => ({ ...row })) // 선택사항
});

const filtered = table.filteredList([
  { name: 'John', type: 'string', like: true },
  { age: 30, type: 'number' }
]);

const sorted = table.sortedList(filtered, ['name:asc']);
const paged = table.selectRows(10, 0, filtered, ['age:desc'], true);

API 설명

constructor(dataSource, options?)

  • dataSource: 객체 배열 (원본 데이터)
  • options.primaryKey: 고유 키로 사용할 컬럼명 (중복 삽입 방지)
  • options.dataProcessing: 최종 데이터 처리 콜백

filteredList(conditions)

  • 조건에 맞는 row 리스트 반환
  • AND/OR 트리 구조도 지원

sortedList(rows, sorts)

  • sorts: ['key:asc', 'key2:desc'] 형식

selectRows(limit?, offset?, conditions?, sort?, meta?)

  • 페이징 + 필터링 + 정렬을 결합한 메서드
  • meta = true일 경우 { result, meta } 반환

insertRow(item)

  • primaryKey 중복 검사 후 삽입

updateRow(conditions, newItem?)

  • 조건을 만족하는 첫 row 수정 (또는 제거)

deleteRow(conditions)

  • 조건을 만족하는 첫 row 제거

selectRow(conditions)

  • 조건을 만족하는 첫 row 반환

ConditionItem 구조

type ConditionItem = {
  [key: string]: any;
  type?: 'string' | 'number' | 'boolean';
  required?: boolean;
  like?: boolean;
};
  • like: 부분일치 (includes) 검색
  • required: 필수값 여부
  • type: 타입 검사 수행 여부

ConditionNode 구조

type ConditionNode =
  | { logic?: 'AND' | 'OR'; conditions: ConditionNode[] }
  | ConditionItem;

복합 조건을 AND 또는 OR 로 구성할 수 있습니다.


예시

const table = new TableData([
  { id: 1, name: 'Alice', age: 25 },
  { id: 2, name: 'Bob', age: 30 }
]);

const result = table.selectRows(10, 0, [
  { name: 'ali', type: 'string', like: true }
]);

console.log(result);
const table = new TableData([
  { id: 1, name: 'Alice', role: 'admin' },
  { id: 2, name: 'Bob', role: 'user' },
  { id: 3, name: 'Charlie', role: 'guest' }
]);

const result = table.selectRows(10, 0, {
  logic: 'OR',
  conditions: [
    { role: 'admin' },
    { role: 'guest' }
  ]
});

console.log(result);
// 결과: Alice 와 Charlie의 데이터가 반환됩니다.

License

ISC