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

config-brick

v3.0.0

Published

simple config builder for some complex config file,and you can add brick by own template

Downloads

25

Readme

config-brick 3.0

CircleCI

use standard brick function to build complex config easier

install

yarn add config-brick
# or
npm install config-brick

use with sync functions

const fn0 = () => {
  console.log('hello')
}
const fn1 = conf => {
  conf.a = 1
}
const fn2 = conf => {
  conf.b = 2
  return conf
}
const fn3 = conf => {
  conf.c = 3
  return {
    d: 4
  }
}
const fn4 = 3

lay function, like a pipe

const { lay } = require('config-brick')

const conf1 = lay()() // {}

// use initial value,default is {}
const conf2 = lay()({ initial: 'this is a initial seed' }) // {initial:'this is a initial seed'}
// with no returned function,it will use pre result
const conf3 = lay(fn1)() // {a:1}
const conf4 = lay(fn1, fn2)() // {a:1,b:2}
const conf5 = lay(fn1, fn2, fn3)() // {d:4} because fn3 return {d:4}
const conf6 = lay(fn4)() // {}  fn4 not a function,return pre result

use with Async Function

// notice should resolved a function,not the conf value
const fn5 = new Promise((resolve, reject) => {
  // give a name,for debug
  const fn5Brick = conf => {
    conf.e = 5
  }
  // this is function
  resolve(fn5Brick)
})

const fn6 = new Promise((resolve, reject) => {
  const fn6Brick = conf => {
    conf.f = 6
    return conf
  }
  resolve(fn6Brick)
})

use lay with async function

const { lay } = require('config-brick')

// detect it has async function ,so p will be a Promise instance
const p = lay(fn5, fn6)()

p.then(conf => {
  // {e:5,f:6}
})

you can mix sync function and async function,that's ok

const p = lay(fn1, fn5, fn6)()
p.then(conf => {
  // {a:1,e:5,f:6}
})

with control flow

const { when, lay } = require('config-brick')

const conf = lay(
  fn1, //
  when(true, [fn2])
)()

// {a:1,b:2}

const p1 = lay(
  fn1, //
  // here fn4 is async,so final will be a Promise
  when(true, [fn5])
)
p1.then(conf => {
  // {a:1,e:5}
})

pipe

const { pipe } = require('config-brick')

// pipe function is  like `lay`,but this only support sync function,
pipe(fn1, fn2)() // {a:1,b:2}

pipe(fn5)() // Error

pipeAsync

const { pipeAsync } = require('config-brick')
// pipeAsync function is  like `lay`,but it will always return a Promise
const p = pipeAsync(fn1)() // it will be a Promise
p.then(conf => {
  // {a:1}
})

merge

const { merge } = require('config-brick')
// notice here is,merge(right value)(left value),data always last 
merge({ a: 1, b: [1] })({ a: 2, b: [2] })
// -> {a:1,b:[1,2]}