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

recursive-assign

v1.0.1

Published

recursive assign

Downloads

153

Readme

recursive-assign

A TypeScript library for recursively assigning properties from one object to another with support for function-based transformations.

Features

  • 🚀 Written in TypeScript with full type safety
  • 📦 Supports both ESM and CommonJS
  • 🔄 Recursive deep assignment
  • 🛡️ Prototype pollution protection
  • ⚡ Zero dependencies (removed lodash)
  • 🧪 Comprehensive test suite with Vitest

Installation

npm install recursive-assign

Usage

ESM (Recommended)

import recursiveAssign from 'recursive-assign'

const target = {
  x: '3',
  y: true,
  z: {
    ff: 'as',
    gg: 0,
    hh: {
      kl: 'sa'
    },
    ll: 'sdf',
    arr: [7],
    func: 'sd'
  }
}

const source = {
  x: 6,
  y: false,
  z: {
    ff: 'as8',
    gg: 56,
    jj: 'asd',
    hh: {
      kl: (original: string) => original + '5', // Function to transform original value
      hhg: 'sdf'
    },
    arr: '90',
    func: () => () => 'safds' // Replace with a function
  }
}

recursiveAssign(target, source)

console.log(target.x) // 6
console.log(target.y) // false
console.log(target.z.ff) // 'as8'
console.log(target.z.hh.kl) // 'sa5' (transformed by function)
console.log(target.z.ll) // 'sdf' (unchanged)
console.log(target.z.hh.hhg) // 'sdf' (added)
console.log(target.z.arr) // '90'
console.log(target.z.func()) // 'safds'

CommonJS

const recursiveAssign = require('recursive-assign').default
// or
const { recursiveAssign } = require('recursive-assign')

API

recursiveAssign<T>(target: T, source: Record<string, any>): T

Recursively assigns properties from the source object to the target object.

Parameters:

  • target: The target object to assign properties to
  • source: The source object to copy properties from

Returns: The modified target object

Behavior:

  • Plain objects are merged recursively
  • Functions in the source object are called with the original value from the target
  • Other values are assigned directly
  • Prototype pollution is prevented (ignores __proto__, constructor, prototype)

Development

Building

npm run build

This creates:

  • dist/esm/ - ES modules
  • dist/cjs/ - CommonJS modules
  • dist/types/ - TypeScript declarations

Testing

npm test        # Run tests in watch mode
npm run test:run # Run tests once

License

MIT