Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

suppplant

devotis291MIT1.1.1

Crockford's .supplant method but with support for multiple level objects

supplant, suppplant

readme

Build Status npm version

Suppplant -- yes, 3 p's

This is officially a thing now. Suppplant with 3 p's. It's Crockford's supplant method but with support for multiple level objects. I needed it today. It was asked before and answered in 2012. The credits for the solution without the new options object go to Bergi who posted the answer back then.

Usage

const suppplant = require('suppplant')

suppplant('{we.should.all.be.friends}', {
  we: {
    should: {
      all: {
        be: {
          friends: 'Yes'
        }
      }
    }
  }
})
// 'Yes'

suppplant('{we.should.all.be.friends}', {
  somethingelse: {}
})
// '{we.should.all.be.friends}'

suppplant('{we.should.all.be.friends}', {
  we: {
    should: {
      all: {
        be: {
          friends: true
        }
      }
    }
  }
}, {boolean: true}) // <-- Check out the new options object!
// 'true'

suppplant('{we.should}', {
  we: {
    should: {
      all: {
        be: {
          friends: true
        }
      }
    }
  }
}, {stringify: true})
// '{"all":{"be":{"friends":true}}}'

suppplant('{we.should.all.be.friends}', {
  somethingelse: {}
}, {clear: true})
// ''

// but,

suppplant('{we.should}', {
  we: {
    should: {
      all: {
        be: {
          friends: true
        }
      }
    }
  }
}, {clear: true})
// '{we.should}'

// Does not clear, because there is that data

Install

npm install suppplant

Credits

As mentioned before, credits for the 1.0 solution go to Bergi.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[1.1.1] - 2020-06-03

Added

  • CHANGELOG.md

Changed

  • Upgrade dependencies

[1.1.0] - 2017-07-06

Added

  • Release with options config

...