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

@swnb/dct

v0.1.0

Published

dct algorithm implement in typescript

Readme

@swnb/dct

dct algorithm implement in typescript

for example

luma image before dct

luma

after dct, you can use idct to recovery origin image

dct

install

use pnpm

  pnpm i @swnb/dct

use npm

  npm i @swnb/dct

usage

prepare example data

  const example = [
    [65, 76, 82, 66, 18, 32],
    [12, 87, 9, 2, 54, 78],
    [74, 45, 18, 48, 60, 72],
    [65, 2, 54, 404, 800, 905],
  ]

discrete cosine transform

  import { dct } from '@swnb/dct'

  const result = dct(example)

  console.log(result) 
  // [
  //   [
  //     638.5003262854817, -416.9193200063309, 154.99999999999983, 42.4578222082416, -43.01259505462728,
  //     -17.244243642209376,
  //   ],
  //   [
  //     -512.6170218697843, 578.6135814300578, -184.03403633138637, -109.98075816639899,
  //     29.645534009728465, -12.201804240974509,
  //   ],
  //   [
  //     410.2895319161823, -385.13955429855645, 75.4999999999998, 66.54447134560958, 8.660254037844224,
  //     12.49428061324591,
  //   ],
  //   [
  //     -188.89844420398651, 249.46420106733234, -75.84671035435811, 2.2508146252807193,
  //     52.71203828296457, 1.9283180367658657,
  //   ],
  // ]

inverse discrete cosine transform

  import { idct } from '@swnb/dct'

  const result = dct(example)

  const originData = idct(result)

  console.log(originData)
  // [
  //   [
  //     64.99999999999993,
  //     75.99999999999999,
  //     81.99999999999997,
  //     65.99999999999996,
  //     17.999999999999897,
  //     31.999999999999893
  //   ],
  //   [
  //     11.99999999999998,
  //     87.00000000000003,
  //     8.999999999999943,
  //     1.9999999999999762,
  //     53.99999999999998,
  //     78.00000000000009
  //   ],
  //   [
  //     73.99999999999994,
  //     45.000000000000036,
  //     17.999999999999922,
  //     47.99999999999986,
  //     59.99999999999982,
  //     71.99999999999982
  //   ],
  //   [
  //     64.99999999999974,
  //     2.00000000000048,
  //     53.99999999999999,
  //     404.0000000000001,
  //     799.9999999999999,
  //     904.9999999999995
  //   ]
  // ]

use interface

// if you implement Matrix or MatrixPromise

interface Matrix {
  getValue: (x: number, y: number) => number
}

interface MatrixPromise {
  getValue: (x: number, y: number) => Promise<number>
}

you can use dctMatrix, dctMatrixPromise, idctMatrix, idctMatrixPromise to process matrix

  import { dctMatrix, idctMatrix, dctMatrixPromise, idctMatrixPromise, Matrix, MatrixPromise } from '@swnb/dct'

  declare const m: number // matrix's width
  declare const n: number // matrix's height
  declare const matrix: Matrix // matrix implement { getValue: ( x, y ) => number }  0 <= x < m , 0 <= y < n

  declare const matrixPromise: MatrixPromise

  const result1 = dctMatrix(matrix, m, n)

  const result2 = await dctMatrixPromise(matrixPromise, m, n)