1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 10:19:24 +02:00
Oinktube/node_modules/safe-json-parse
Daniel 2a9630258f https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556
Also check the lang in case insensitive
2022-03-14 14:28:38 -03:00
..
examples Moving to node_modules folder to make easier to upgrade 2021-10-26 14:52:45 -03:00
test https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
.npmignore https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
.testem.json https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
.travis.yml https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
callback.js https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
LICENCE https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
package.json https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
README.md https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
result.js https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00
tuple.js https://github.com/WWBN/AVideo/issues/6345#issuecomment-1067056556 2022-03-14 14:28:38 -03:00

safe-json-parse

build status dependency status

Parse JSON safely without throwing

Example (callback)

var safeParse = require("safe-json-parse/callback")

safeParse("{}", function (err, json) {
    /* we have json */
})

safeparse("WRONG", function (err) {
    /* we have err! */
})

Example (tuple)

var safeParse = require("safe-json-parse/tuple")

var tuple1 = safeParse("{}")
var json = tuple1[1] /* we have json */

var tuple2 = safeparse("WRONG")
var err = tuple2[0] /* we have err! */

var tuple3 = safeParse(something)
if (tuple3[0]) {
    var err = tuple3[0]
    // handle err
} else {
    var json = tuple3[1]
    // handle json
}

Example (result)

var Result = require('rust-result')
var safeParse = require('safe-json-parse/result')

var result1 = safeParse("{}")
var json = Result.Ok(result1) /* we have json */

var result2 = safeparse("WRONG")
var err = Result.Err(result2) /* we have err! */

var result3 = safeParse(something)
if (Result.ifErr(result3)) {
    var err = Result.Err(result3)
    // handle err
} else if (Result.ifOk(result3)) {
    var json = Result.Ok(result3)
    // handle json
}

Installation

npm install safe-json-parse

Contributors

  • Raynos

MIT Licenced