Nine Pedestrians Mesmerized

    js-safe-json

    1.0.8 • Public • Published

    about

    handle json data with safe & easy way

    install

    npm install js-safe-json
    

    dev

    npm run start
    

    run test

    npm run test
    

    usage

    import {
      fetchObject,
      fetchBoolean,
      fetchString,
      fetchNumber,
      fetchArray } from 'js-safe-json';
    
    // your json data
    let jsonData = {
      a: [
        {
          a1: '',
          a2: true,
          a3: false,
        },
        {
          a1: [1, 2, 3, 4],
          a2: true,
          a3: false,
        },
      ],
      b: {
        b1: 12,
        b2: 12.0,
        b3: 12.01,
        b4: 12.001
      },
      c: 0,
      d: null,
      e: '0'
    };
    
    // it is safe,if data not expect value,it will return default value
    // object  default value: {}
    // boolean default value: false
    // string  default value: ''
    // number  default value: 0
    // array   default value: []
    
    let object = fetchObject(jsonData, 'b');
    let boolean = fetchBoolean(jsonData, 'b');
    let string = fetchString(jsonData, 'e');
    let number = fetchNumber(jsonData, 'b', 'b1');
    let array = fetchArray(jsonData, 'a');
    

    License

    Copyright (C) 2019 fewspider

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    Keywords

    Install

    npm i js-safe-json

    DownloadsWeekly Downloads

    6

    Version

    1.0.8

    License

    MIT

    Unpacked Size

    14.3 kB

    Total Files

    8

    Last publish

    Collaborators

    • fewspider