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

@evoja/packageoid

v1.0.0

Published

Reads `package.json` as object and overrides it with `process.env.npm_package_...` values which could be defined in `.npmrc` files

Downloads

1

Readme

packageoid npm version Build Status

Reads package.json as object and overrides it with process.env.npm_package_... values which could be defined in .npmrc files

packageoid

Reads config of the module and applies environment variables as user's replacement.

Assume our package.json has following config:

{
  "config": {
    "a": 1,
    "b": "2",
    "c": "m"
  },
  "x": "y",
  "script": {
    "sandbox": "node sandbox.js"
  }
}

And sandbox.js contains:

var packageoid = require('@evoja/packageoid')
var package_json = packageoid(module)

Let's call npm run sandbox. In this case package_json object will be equals

{
  config: {
    a: 1,
    b: '1',
    c: 'm'
  },
  x: 'y',
  script: {
    sandbox: 'node sandbox.js'
  }
}

The most interesting part is package_json.config which equals to

{
  a: 1,
  b: '1',
  c: 'm'
}

If we have the .npmrc file with following content:

fooproject:a=10
fooproject:b=10
fooproject:d=10

Then we have package_json.config equal to

{
  a: 10,
  b: '10',
  c: 'm'
}

We also may call the command: npm run sandbox --fooproject:a=20 --fooproject:b=20 package_json gets the content:

{
  a: 20,
  b: '20',
  c: 'm'
}

It tries to keep types of original fields.

package,    env => result

'a',        'b' => 'b'
'a',        '2' => '2'
 1,         'b' =>  1
 1,         '2' =>  2
{a: 10},    '2' => {a: 10}
[10, 'hi'], '2' => [10, 'hi']

Actually when config is set to null or undefined, then environment variable equals to empty string. In this case we get following:

 1,  '' => 0
'a', '' => ''

packageoid.merge

Takes two arguments default_conf and user_conf it makes a deep copy of the default_conf, and applies the user_conf to it. The user_conf overrides mentioned fields of the default_conf.

var packageoid = require('@evoja/packageoid')
var default_conf = {...}
var user_conf = {...}
var conf = packageoid.merge(default_conf, user_conf)

It has some rules. It does not replace anything by anything. It tries to keep types of original fields.

default | user | result --------|------|------- string | string | user's string string | number, object, array | type cast user's value to string 1 -> '1'{} => '[object Object]'[10, 'hi'] => '10,hi' number | number | user number number | string | converts user's string to number or keeps default on failure number | object, array | keeps default object | object | deep merge with user's object object | number, string, array | keeps default array | number, string | keeps default array | array | replace whole array with user's array, does not merge array values array | object | builds new array where specific inicies were replaces with merges with user's values value | undefined | keeps default value | null | is not specified yet, hovewer behaves somehow undefined/unexisting | value | user's value. Does not make deep copy

Examples

'a', 'b'        => 'b'
'a',  1         => '1'
'a', {}         => '[object Object]'
'a', [10, 'hi'] => '10,hi'`
 1,   2         =>  2
 1,  'a'|{}|[]  =>  1

{a: 10, b: '20', c: 30}, {a: '1', b: 2, d: 'x'} => {a: 1, b: '2', c: 30, d: 'x'}

{a: 10},             1|'a'|[]     => {a: 10}
[10, 'hi'],          1|'a'        => [10, 'hi']
[10, 'hi', {a: 30}], [1]          => [1]
[10, 'hi', {a: 30}], {2: {b: 40}} => [10, 'hi', {a: 30, b: 40}]