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

robjectory

v1.1.1

Published

A global registry to handle configs and flags

Downloads

2

Readme

robjectory

A global registry to handle configs and flags

Description

Developers always declared placed the constants, flags and application configs in different files. Here we provide a global registry to handle them. Global variable is not an evil, in case you know what you are doing.

Priciples

Semantic key

The key name of object literals in JavaScript is case sensitive. In this module, all key names in registry is case insensitive because intuitively it maintains the same semantic meaning.

Predictable mutability

Developers now clearly knows whether the global variables are immutable at the very beginning.

Get Started

$ npm install robjectory

API Reference

var robjectory = require('robjectory');

robjectory.register (key, value, options)

key is a string representing the name of key. value is optional indicating the value of the key. Default is the name of key. options is an optional object for advanced configuration.

  • options.ignoreCapital is a boolean indicating the format of key, the written style of constants and global variables commonly uses UPPERCASE. Default is false.
  • options.isMutable is a boolean indicating the mutability of the key-value pair. Once the key is registered, the corresponding value cannot be modified if this boolean is set to false. Default is false.
  • options.isDual is a boolean indicating the duality of the key-value pair. It can be used to search the key by value and vice versa. The dual will follow the same mutability and name convention.
robjectory.register('flag');
// true
robjectory.register('FlAg');
// false
robjectory.register('constant', 123);
// true
robjectory.register('newFlag',{
    ignoreCapital: true
});
// true
// the key is 'newFlag', just follow the input

robjectory.mutate (key, value)

It returns true after mutation. Return false if the value is immutable.

robjectory.mutate is the only method that can mutate the value in the registered key-value pair. Mutable variables makes the application unpredictable. Let's imagine if the global configuration setting is changed in some file and cause conflict, it's hard to point out where it changes the value. That's why all key-value pair here is unique and immutable by default once the key is registered.

If developers still want to use mutable variables, it's allowed in our module, but they do need to set the option manually so they acknowledge such variable/config is mutable.

robjectory.register('mutable','initialValue',{
    isMutable: true
});
// true { MUTABLE: 'initialValue' }
robjectory.mutate ('mutable','newValue');
// true { MUTABLE: 'newValue' }

robjectory.isMutable (key)

Check whether the value in a registered key-value pair is mutable.

robjectory.register('mutable','initialValue',{
    isMutable: true
});
robjectory.isMutable ('mutable');
// true

robjectory.hasKey (key)

Check whether the key is registered.

robjectory.register('hasKeyTest');
robjectory.hasKey('hasKeyTest');
// true

robjectory.remove (key)

It returns true if the key-value pair is successfully removed. Returns false indicating the non-exist key.

robjectory.register('flag');
// the corresponding value is 'flag'
robjectory.remove('flag');
// true
robjectory.remove('flag');
// false because the key-value pair is deleted in the last step

robjectory.getValue (key)

It returns the corresponding value. If the key is not registered, it returns undefined.

robjectory.getValue('no-flag');
// undefined
robjectory.register('flag');
robjectory.getValue('flag');
// 'flag'

robjectory.findKeyName (key)

It returns the actual name of key used in object.

robjectory.register('flag');
robjectory.findKeyName('flag');
// FLAG
robjectory.findKeyName('flAg');
// FLAG
robjectory.register('tHiSiSmYkEy','value',{
    ignoreCapital: true
});
robjectory.findKeyName('thisismykey');
// tHiSiSmYkEy

License

MIT

Copyright

Copyright (C) 2015 Tony Ngan, released under the MIT License.