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

object-parse

v1.1.4

Published

An Object parsing script with options/settings pairing and functional tools.

Downloads

52

Readme

object-parse

A portable Object manager for settings/options paired data

NPM

Author: Robert Edward Steckroth II

Digital Persona: Surgemcgee, Bustout [email protected]

Licence: GPLv3

Description: Parses and verifies objects with a getter/setter methodology. This module/library also incorperates a command line parser for convience.

Features:

  • Reduces errors from mis-configured cli input
  • Object oriented for project integration

**Prolouge: ** the object-parse module contains two primary built-in members: settings and options. Both of these members are idempotant object/function hybrid Objects which operate the same regardless of how it is called. Both methods of direct property setting or self function calling can/should be utilized for maximum eficiantcy.

The command line parser uses the process environment variable use within Nodejs and parses the command line input stored therein. The parser supports: String, Boolean, Number, and Object.

The cli input must be separated by a = without any non-quated space next to it.


options

Options are used as template data for allowable settings. An option must be an Array which can be empty or contain any number of values. An option can be set in two ways: with object-parse.options() or by directly setting a property to the object-parse.options member.

The options array values are type sensitive. When a incorrect type or value is applied with the object-parse.settings member, a default value will be used. The default value will be the first index of the corisponding options Array value. If the array is empty, undefined will be set as the default setting.

Warning: Do not do not modify any options Array values with methods, e.g. options.port.pop(), options.port.splice(1). The options must be set directly with the = operater for internal setting reasons

  • Using _object-parse.options as a function

syntax: object-parse.options({port: [8090, 8085]}, Object, etc..)

The above example shows how to specify a "port" option to the module with two availible choices (8090, 8085).

> Any number of objects can be passed into the options function for convience,
e.g. object-parse.options({port: [8090, 8085], app_name: [""]}, {url:     ["https://localhost, "http://127.0.0.1"]})
  • Using object-parse.options as an object

    syntax: object-parse.options.port = [8090, 8085]

    The above example shows how to specify a "port" option to the module with two availible choices (8090, 8085).


###settings

Settings are set with this member. They are compared against the options value Arrays for valididity. If a valid setting is set or passed in this member it will then be stored within itself. Otherwise, the current or default options value will be set to the member.

  • Using _object-parse.settings as a function

    syntax: object-parse.settings({port: 8080, app_name: "My cool app"}, Object, etc..)

    The above example shows how to specify a "port" and "app_name" settings to the module. Both of these will be validated against the options and used if appropreate.

  • Using _object-parse.settings as an object

    syntax: object-parse.settings.port = 8080, object-parse.settings.app_name = "My cool"`

    The above example shows how to specify a "port" and "app_name" settings to the module. Both of these will be validated against the options and used if appropreate.


###parse_cli

  • Using object-parse.parse_cli()

    Note: This member is to be used with the Nodejs process environment variable only.

    syntax: var obj = object-parse.parse_cli() or object-parse.settings(object-parse.parse_cli())

    The parse_cli() function takes zero arguments and returns an object from the process.argv strings.

    Example: Providing this cli input string --> node Test_me.js data="{'log file': '/home/surgemcgee/log/njs_logs.js', 'another': {'name':'bob'}}" test=true name=Robert age=32 type=" Human" 'another_obj= {"cool": true}'

object-parse.parse_cli() will return the following Object -->

{
  "data": {         // Object
    "log file": "/home/surgemcgee/log/njs_logs.js",  // String
    "another": {    // Object
      "name": "bob" // String
    }
  },
  "test": true,      // Boolean
  "name": "Robert",  // String
  "age": 32,         // Number
  "type": " Human",  // String
  "another_obj": {   // Object
  "cool": true       // Boolean
  }
}

Given the object below, the debug object will only be set to boolean true or false. All others will be rejected and the default value (true) will be use.

When the option array length is 0 or 1 (like app_name, message, or extra below), options will allow any settings to be set and used. If two or more values are supplied, only those can be set to the settings member.

    // example object-parse options declaration
    object-parse.options({
             debug: [true, false, "Verbose"], // Allow only _true_, _false_, or _"Ok"_ into _data.settings_ and set _true_ as default
             app_name: ["My server"], // Allow anything to be set and use String("My server") as the default value
             message: [""], // Allow anything and set and use an empty string as the default
             extra: [], // Allow anything to be set and set and use _undefined_ as default
             port: [8085, 8080], // Allow only Numbers([8085, 8080]) to be set as the port
    })
> Options can be appended to _the object-parse.options()_ object by passing in new objects. Any colliding qualifiers will be over-written.