Neutralize Pesky Miscreants

    object-information

    0.4.2 • Public • Published

    object-information

    NPM Version NPM Downloads License MIT Dependencies

    What?

    Object Information is a library that returns a formatted string with informarion about what an object contains.

    Why?

    This was developed to give better results when combined with approval tests. JSON.stringify by itself does not give enough information.

    I wanted something that could handle functions, signet signatures, and errors within the output.


    asInformationString

    The 'asInformationString' method, takes an object and returns the most detailed string.

    const { asInformationString } = require('object-information');
     
    const enforcedFunction = signet.enforce(
                'a:number, b:int => number',
                function enforcedFunction(a, b) {
                    return a * b;
                }
            );
     
    const testObject = {
                'a String property': 'this is a string',
                'an error property': new Error('this is an error'),
                'a number property': 42,
                'an enforced function': enforcedFunction,
                'an array property': ['life', 'universe', 'everything', 42],
            };
     
    const informationString = asInformationString(testObject);

    The variable 'inforamtionString' contains:

    `{
        "a String property": "this is a string",
        "an error property": "Error: this is an error",
        "a number property": 42,
        "an enforced function": "Function: enforceDecorator [a:number, b:int => number]",
        "an array property": [
            "life",
            "universe",
            "everything",
            42
        ]
    }`

    asBasicInformationString

    The method 'asBasicInformationString' removes the function signatures.

    `{
        "a String property": "this is a string",
        "an error property": "Error: this is an error",
        "a number property": 42,
        "an enforced function": "Function: enforceDecorator",
        "an array property": [
            "life",
            "universe",
            "everything",
            42
        ]
    }`

    asFormattedJsonString

    The method 'asFormattedJsonString' is just a wrapper arround JSON.stringify(value, null, 4);.

    `{
        "a String property": "this is a string",
        "an error property": {},
        "a number property": 42,
        "an array property": [
            "life",
            "universe",
            "everything",
            42
        ]
    }`

    asJsonString

    The method 'asJsonString' allows you to determine the indent.

    The call asJsonString(testObject, 2); returns:

    `{
      "a String property": "this is a string",
      "an error property": {},
      "a number property": 42,
      "an array property": [
        "life",
        "universe",
        "everything",
        42
      ]
    }`

    Where as the call sJsonString(testObject); returns:

    '{"a String property":"this is a string","an error property":{},"a number property":42,"an array property":["life","universe","everything",42]}'

    asGridString

    The method 'asGridString' takes in an array of arrays, and then prints returns it as a grid.

    const data = [
        [1, 2, null],
        [4, undefined, 5],
        [6, { property: 7 }, 8]
    ];
     
    asGridString(data);

    This call returns:

    .......1........|.......2........|......null......
    .......4........|.."undefined"...|.......5........
    .......6........|.{"property":7}.|.......8........
    

    Keywords

    none

    Install

    npm i object-information

    DownloadsWeekly Downloads

    9

    Version

    0.4.2

    License

    MIT

    Unpacked Size

    16.2 kB

    Total Files

    17

    Last publish

    Collaborators

    • jasonkerney