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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sullux/fp-light-set

v0.0.5

Published

A lightweight functional library for functional composition and object composition.

Downloads

14

Readme

home

fp-light-set

npm i @sullux/fp-light-set
source
test

The set function returns a newly-composed object or array with the given deep property set to the given value.

set

set(path, value, input)

  • path: string, number or array of strings/numbers. This is the key, index or path of keys/indexes to the property of the input object.
  • value: the new value to set on the input object.
  • input: the object or array on which the new value is being set.

The set function creates a deep copy of the input with the new value interpolated into the result at the offset denoted by the path. If parts of the path are missing, those parts are created. If a path part is a number, it is assumed to be an offset into an array; otherwise, it is assumed to be a property of an object.

The set function can be particularly useful in mapping operations as in the following example.

const { map } = require('@sullux/fp-light-map')
const { set } = require('@sullux/fp-light-set')

const people = [
  { name: 'jane' },
  { name: 'jamal' },
  { name: 'zhang' },
]

const inactive = map(set('active', false))

inactive(people)
/*
[
  { name: 'jane', active: false },
  { name: 'jamal', active: false },
  { name: 'xing', active: false },
]
*/

setOn

setOn(input, path, value)

Same functionality as set, but with the arguments rearranged so that the value is the most significant (last) argument.

const records = pipe(
  map(setOn({}, 'value'))
  map(set('createTime', Date.now())),
  Array.from,
  setOn({}, 'records')
)

console.log(records([1, 2, 3]))
/*
{
  Records: [
    { value: 1, createTime: 1552058411957 },
    { value: 2, createTime: 1552058411958 },
    { value: 3, createTime: 1552058411959 },
  ]
}
*/

setValue

setValue(input, key, value)

  • input: the object on which to set the value
  • key: the input key or index at which to set the value
  • value: the new value of the key or index

The setValue function creates a shallow copy of the input object/array with the value interpolated into the result at the given key.

const { setValue } = require('@sullux/fp-light-set')

setValue({ foo: 7, bar: 'baz' }, 'foo', 42)
// { foo: 42, bar: 'baz' }

setValue([7, 8, 13], 1, 42)
// [7, 42, 13]

setObjectValue

setObjectValue(input, key, value)

The setObjectValue function creates a shallow copy of the input object with the value interpolated into the result at the given key. This is the default behavior of setValue when the input is not an array.

setArrayValue

setArrayValue(input, key, value)

The setArrayValue function creates a shallow copy of the input array with the value interpolated into the result at the given key. This is the default behavior of setValue when the input is an array.