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

fructify

v1.0.2

Published

Replaces null/undefined values with random fruit emojis to keep your app sweet and safe.

Readme

🍉 Fructify

Replace boring null and undefined values with delicious fruit emojis — because life's too short for missing data. 🍎🍌🍇

![npm version](https://img.shields.io/npm/v/fructify)
![license](https://img.shields.io/npm/l/fructify)

## ✨ What is Fructify?

Fructify is a lightweight JavaScript utility that replaces null, undefined, or even other "falsy" values with random fruit emojis. It's perfect for demos, pre-production environments, or simply making your logs and API responses more… tasty.

## 🚀 Features

- 🍍 Replace null and undefined with random fruits
- 🍑 Optionally replace all falsy values (`""`, `0`, `false`)
- 🍓 Works in both Node.js and browser environments  
- 🍒 Includes a Proxy-based mode for automatic substitution
- 🥝 Safe recursion with maximum depth protection
- 🍊 Custom replacer function for full control
- 🥭 Tiny, dependency-free, and fun!

## 📦 Installation

```bash
npm install fructify
# or
yarn add fructify

🧩 Basic Usage

const { fructify, fructifyObject } = require('fructify');

// Simple replacement
console.log(fructify(null)); // 🍉

// Nested object example
const data = {
  name: null,
  city: 'São Paulo', 
  age: undefined,
};

console.log(fructify(data));
// -> { name: '🍎', city: 'São Paulo', age: '🍌' }

// Proxy mode (dynamic replacement)
const fruity = fructifyObject({ mood: null, level: undefined });
console.log(fruity.mood);  // 🍍
console.log(fruity.level); // 🍓

⚙️ Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | replaceFalsy | boolean | false | Replace falsy values like "", 0, or false | | customReplacer | function | null | Define your own replacement logic | | maxDepth | number | 10 | Prevents infinite recursion in nested objects |

Example:

fructify(data, { replaceFalsy: true });

🧠 Advanced Usage

🎭 Method Wrapping

Higher-order function (works everywhere):

const { fructify } = require('fructify');

const withFructify = (fn) => (...args) => fructify(fn(...args));

const getUser = withFructify(() => ({ name: null, email: undefined }));
console.log(getUser()); // -> { name: '🍎', email: '🍌' }

Manual method wrapping:

const { fructify } = require('fructify');

class UserService {
  findUser() {
    return { name: null, age: undefined, active: true };
  }
}

// Wrap the method
const originalMethod = UserService.prototype.findUser;
UserService.prototype.findUser = function(...args) {
  const result = originalMethod.apply(this, args);
  return fructify(result);
};

const service = new UserService();
console.log(service.findUser());
// -> { name: '🍒', age: '🍇', active: true }

🎨 Custom Replacement

// Use your own replacement logic
const data = { value: null, items: [] };

const result = fructify(data, {
  customReplacer: (value) => {
    if (value === null) return '🚫';
    if (value === undefined) return '❓'; 
    if (Array.isArray(value) && value.length === 0) return '📭';
    return value;
  }
});

console.log(result);
// -> { value: '🚫', items: '📭' }

🛠️ Framework Integration

React Hook

import { useMemo } from 'react';
import { fructify } from 'fructify';

export const useFructify = (data, options) => {
  return useMemo(() => fructify(data, options), [data, options]);
};

// Usage in component  
function UserProfile({ userData }) {
  const safeUser = useFructify(userData, { replaceFalsy: true });
  return <div>Hello {safeUser.name}!</div>; // Always shows a fruit 🍎
}

Express.js Middleware

const { fructify } = require('fructify');

const fructifyMiddleware = (options) => (req, res, next) => {
  const originalSend = res.send;
  res.send = function(data) {
    if (typeof data === 'object') {
      data = fructify(data, options);
    }
    originalSend.call(this, data);
  };
  next();
};

app.use(fructifyMiddleware({ replaceFalsy: true }));

🧪 Development

# Clone and install
git clone <your-repo>
cd fructify
npm install

# Run tests
npm test

# Run demo
node demo.js

🧃 Why?

Because not everything in life should throw TypeError: Cannot read properties of null.

Sometimes, you just need more fruit. 🍑

💡 Inspiration & The Null Safety Discussion

The Billion-Dollar Mistake

"I call it my billion-dollar mistake..." — Tony Hoare, inventor of the null reference

While modern languages have built-in null safety, JavaScript developers still face the classic nightmare:

user.profile.address.city // 💥 Cannot read properties of null

Where Fructify Fits

Fructify bridges the gap between JavaScript's dynamic nature and proper null handling:

// Instead of silent failures:
user?.name || 'Unknown' // ❌ What was wrong?

// Fructify tells you exactly what happened:
fructify(user?.name) // ✅ '🍎' = it was null!

The Philosophy

| Approach | Philosophy | |----------|------------| | TypeScript | Prevent errors at compile time | | Optional Chaining | Gracefully handle missing properties | | Fructify | Make invisible problems visible and delightful |

Perfect For

  • 🚀 Prototyping & MVP development
  • 🔍 API response exploration
  • 🎓 Educational projects
  • 🐛 Debugging with visibility

Because sometimes, the best fix for a technical problem is a creative approach. 🍎✨

📄 License

MIT © Gustavo Damasceno