This package has been deprecated

Author message:

THIS PROJECT IS NO LONGER MAINTAINED by clebert

stdjs

0.5.0 • Public • Published

stdjs

A collection of useful utility functions for JavaScript projects.

build status npm version

Installation

npm install stdjs --save

API

isBoolean(value: any): boolean

import isBoolean from 'stdjs/lib/isBoolean';

isCircular(value: any): boolean

import isCircular from 'stdjs/lib/isCircular';

isFinite(value: any): boolean

import isFinite from 'stdjs/lib/isFinite';

isNumber(value: any): boolean

import isNumber from 'stdjs/lib/isNumber';

isObject(value: any): boolean

import isObject from 'stdjs/lib/isObject';

isString(value: any): boolean

import isString from 'stdjs/lib/isString';

isUndefined(value: any): boolean

import isUndefined from 'stdjs/lib/isUndefined';

stringify(value: any, options?: StringifierOptions = {}): string

This function converts a JavaScript value to a well-formatted JSON string.

import stringify from 'stdjs/lib/stringify';

Type of options parameter

type StringifierOptions = {
    indentation?: string;
    newline?: string;
    onBeforeElement?: (value: any, index: number, array: Array<any>) => Array<string>;
    onBeforeProperty?: (value: any, key: string, object: Object) => Array<string>;
};

Default values for options parameter

indentation = '    '
newline = '\n'
onBeforeElement = (() => [])
onBeforeProperty = (() => [])

Example

Program:

const jsonString = stringify({a: ['foo', 'bar', 'baz'], b: 123}, {
    onBeforeElement(value, index, array) {
        if (value === 'bar') {
            return ['', '// This is a comment for an element!'];
        }
 
        return [];
    },
    onBeforeProperty(value, key, object) {
        if (key === 'b') {
            return ['// This is a comment for a property!'];
        }
 
        return [];
    }
});
 
console.log(jsonString);

Output:

{
    "a": [
        "foo",
 
        // This is a comment for an element!
        "bar",
        "baz"
    ],
    // This is a comment for a property!
    "b": 123
}

trimBlank(value: string): string

import trimBlank from 'stdjs/lib/trimBlank';

Package Sidebar

Install

npm i stdjs

Weekly Downloads

12

Version

0.5.0

License

MIT

Last publish

Collaborators

  • clebert