0.3.5 • Published 2 years ago

tucson v0.3.5

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

Build Status

TUCSON - TUne/Convert Your jSON

Tucson (/ˈtuːsɒn, tuːˈsɒn/) is a package to convert JSON key/values to make it fit on your project.

Motivation

We usually want to keep unified code format, such as naming rule, spacing, etc. in project. But when code convention between client side(front-end) and server side(back-end) are different, this would cause some exception on it.

For example, I developed client side with javascript and server side with python. But python usually uses snake_case for parameter name, while javascirpt has been developed, in my case, with camelCase. In this situation, some of the javascript needs to be using snake_case, to receive and handle parameters from server.

So this is why I thought about this. By wrapping response data with this and setup option fit to convention in client side, I could keep codes in unified form.

Thanks for reviewers

Usage

This is still in beta status, so API format/name could be changed by version updates.

Installation

// NPM
$ npm install tucson

// YARN
$ yarn add tucson

Example

let { Tucson, Config } = require('tucson')

const dummyUnderscoreJson = {
  "group_id": 139,
  "user": "inylove82@gmail.com",
  "phone_number": "000-111-2222",
  "salary": "Unknown",
  "is_valid": 0,
  "date": "2014-06-01 12:00"
}

let formedResult = {}
let cctucson = new Tucson(new Config('camelCase'))
cctucson.formed(dummyUnderscoreJson, {
  makeDate: ['date'],
  makeBool: ['is_valid']
}, formedResult)
console.log(formedResult)

...result is...

{
    "groupId":139,
    "user":"inylove82@gmail.com",
    "phoneNumber":"000-111-2222",
    "salary":"Unknown",
    "isValid": false,
    "date":"2014-06-01T03:00:00.000Z"
}

Options


Config

It has single parameter(will be updated more...)

Key NameTypeAvailable ValueDescription
KeyConvertType (optional)string'camelCase', 'snake_case'Converting key data to defined type

Tucson::formed

Definition of formed is:

Tucson.formed(original-object, option, reformed-object)

Second parameter is JSON format option to select converting rule. More options will be updated.

Key NameTypeDescription
excludestringkey of original jsonExclude selected keys in reformed object
makeDatestringkey of original jsonMake value of selected keys as format of Moment.Date
makeBoolstringkey of original jsonMake value of selected keys as boolean.

Contribution

Any type of contribution/feedback(Issue, PR, or Star) is Welcome! Feel free to join.

0.3.5

2 years ago

0.3.4

2 years ago

0.3.2

4 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago