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

truthylens

v0.0.1

Published

`truthylens` menyediakan api untuk memvalidasi data (array, object, atau nilai tunggal) dan mengelola konfigurasi dengan fallback nilai default. Mendukung pemeriksaan nilai `truthy` dan `falsy`, pencatatan bersyarat, serta penggabungan konfigurasi.

Readme

truthylens

truthylens menyediakan api untuk memvalidasi data (array, object, atau nilai tunggal) dan mengelola konfigurasi dengan fallback nilai default. Mendukung pemeriksaan nilai truthy dan falsy, pencatatan bersyarat, serta penggabungan konfigurasi.

Instalasi

npm install truthylens

Penggunaan

// esm
import { truthylens } from 'truthylens'

// commonjs
const { truthylens } = require('truthylens')

validateData(data)

Memvalidasi apakah elemen dalam data adalah truthy atau falsy, dengan memberikan laporan terperinci.

Parameter:

  • data (*): Data yang akan diperiksa.

Mengembalikan:

  • object: Laporan hasil validasi.
console.log(
  truthylens.validateData([
    true,
    false,
    {},
    null,
    [],
    undefined,
    42,
    0,
    '0',
    -0,
    'false',
    0n,
    new Date(),
    NaN,
    -42,
    '',
    12n,
    3.14,
    -3.14,
    Infinity,
    -Infinity,
  ])
)
// { array: [{ index: 0, value: true, isTruthy: true, message: ... }, ...] }

console.log(
  truthylens.validateData({
    a: true,
    b: false,
    c: {},
    d: null,
    e: [],
    f: undefined,
    g: 42,
    h: 0,
    i: '0',
    j: -0,
    k: 'false',
    l: 0n,
    m: new Date(),
    n: NaN,
    o: -42,
    p: '',
    q: 12n,
    r: 3.14,
    s: -3.14,
    t: Infinity,
    u: -Infinity,
  })
)
// { object: [{ key: 'a', value: true, isTruthy: true, message: ... }, ...] }

console.log(truthylens.validateData('Test'))
// { single: { value: 'Test', isTruthy: true, message: ... } }

console.log(truthylens.validateData(0))
// { single: { value: 0, isTruthy: false, message: ... } }

console.log(truthylens.validateData('Yes', null))
// { single: { value: 'Yes', isTruthy: true, message: ... } }

console.log(truthylens.validateData(undefined, 'No'))
// { single: { value: undefined, isTruthy: false, message: ... } }

conditionalLogger(data, condition = 'truthy')

Mencetak elemen truthy atau falsy dari data ke dalam tabel konsol.

Parameter:

  • data (*): Data yang akan diperiksa.
  • condition (string, opsional): Kondisi pencatatan (truthy atau falsy).

Mengembalikan:

  • Tidak ada (hanya mencetak ke konsol).
truthylens.conditionalLogger(
  [
    true,
    false,
    {},
    null,
    [],
    undefined,
    42,
    0,
    '0',
    -0,
    'false',
    0n,
    new Date(),
    NaN,
    -42,
    '',
    12n,
    3.14,
    -3.14,
    Infinity,
    -Infinity,
  ],
  'truthy' /*atau falsy*/
)
// Mencetak elemen dengan nilai truthy dalam tabel.

truthylens.conditionalLogger(
  {
    a: true,
    b: false,
    c: {},
    d: null,
    e: [],
    f: undefined,
    g: 42,
    h: 0,
    i: '0',
    j: -0,
    k: 'false',
    l: 0n,
    m: new Date(),
    n: NaN,
    o: -42,
    p: '',
    q: 12n,
    r: 3.14,
    s: -3.14,
    t: Infinity,
    u: -Infinity,
  },
  'falsy' /*atau truthy*/
)
// Mencetak elemen dengan nilai falsy dalam tabel.

truthylens.conditionalLogger('Hi', 'truthy')
// Mencetak elemen dengan nilai truthy dalam tabel.

truthylens.conditionalLogger(NaN, 'falsy')
// Mencetak elemen dengan nilai falsy dalam tabel.

truthylens.conditionalLogger('Hi', 'falsy')
// Mencetak elemen dengan nilai kosong dalam tabel.

truthylens.conditionalLogger(NaN, 'truthy')
// Mencetak elemen dengan nilai kosong dalam tabel.

ensureConfig(config, defaultConfig)

Menggabungkan konfigurasi pengguna dengan nilai default.

Parameter:

  • config (array|object): Konfigurasi pengguna.
  • defaultConfig (array|object): Konfigurasi default.

Mengembalikan:

  • array|object: Konfigurasi akhir dengan fallback nilai falsy dari defaultConfig.
const userArray = [1, null, 3]
const defaultArray = [0, 2, 4, 5]

console.log(truthylens.ensureConfig(userArray, defaultArray))
// [1, 2, 3, 5]

const userObject = { theme: 'dark', fontSize: null }
const defaultObject = { theme: 'light', fontSize: 14, language: 'en' }

console.log(truthylens.ensureConfig(userObject, defaultObject))
// { theme: 'dark', fontSize: 14, language: 'en' }

console.log(truthylens.ensureConfig('Hello,', ''))
// Hello,
console.log(truthylens.ensureConfig('', 'world!'))
// world!

console.log(truthylens.ensureConfig('', 'Hello,'))
// Hello,
console.log(truthylens.ensureConfig('world!', ''))
// world!

console.log(truthylens.ensureConfig('Hello,', 'world!'))
// Hello,
Sumber truthy dan falsy dilisensikan di bawah Lisensi Creative Commons Attribution-ShareAlike v2.5 atau lebih baru

https://developer.mozilla.org/en-US/docs/Glossary/Truthy https://developer.mozilla.org/en-US/docs/Glossary/Falsy

Donasi

Ko-fi

Lisensi

MIT