0.5.0 • Published 10 years ago

stdjs v0.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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';
0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago