1.0.8 • Published 3 years ago

google-json-style-guide v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Google JSON Style Guide

Software License Build Status npm version npm downloads

Google JSON Style Guide is a NPM library to work under the Google Json Style Guide standard. This package tries to offer facilities to handle the standard, or simply to force it.

Basic Usage

Install

npm i google-json-style-guide

Import

import GjsonResponse from "google-json-style-guide";

Basic usage

const apiVersion = "1.0";
const context = "My Context";
const gjsonResponse = new GjsonResponse(apiVersion, context);

Parse

Dates

* Dates are not automatically transformed

gjsonResponse.format().dateTimeToRFC3339('31-10-2020', 'DD-MM-YYYY');

Camel Case

gjsonResponse.format().toCamelCase(data)

Remove empty, null and undefined

gjsonResponse.format().removeByValue(data['key'])

Parse all response (Except dates)

gjsonResponse.format().formatAll(data);

Responses

List

const results = {};

const data = {
    totalItems: 40,
    itemsPerPage: 10,
    totalPages: 4,
    previousLink: "https://my.url?page=1",
    selfLink: "https://my.url?page=2",
    nextLink: "https://my.url?page=3",
    items: results
};

res.json(gjsonResponse.list(data));

item

const data = {
    id: 2,
    email: "username@email.com",
    firstName: "First",
    lastName: "Last"
};

res.json(gjsonResponse.one(data));

Error

const data = {
    code: "404",
    message: "Not Found"
};

res.status(404).json(gjsonResponse.error(data));

Stored/Updated/Deleted

res.json(gjsonResponse.store(true));
res.json(gjsonResponse.update(true));
res.json(gjsonResponse.delete(true));
1.0.8

3 years ago

1.0.7

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.0

3 years ago