serde_json_lodash
serde_json::Value with lodash.js spec, makes life easier.
Usage
Cargo.toml
[]
= "0.1"
main.rs
extern crate serde_json_lodash;
use json;
Contributes
All implements should be same as lodash as possible
How?
- Every function from lodash.js should be implemented both
fn
andmacro
(for optional parameters usages) - The main inputs and return value should be
serde_json::Value
, except:- If the input parameters are options, not data, using primitive type instead Value
- e.q.
_.chunk(array, [size=1])
=>::check!(json!([1,2,3]), 2)
, size should beusize
, notValue::Number
- e.q.
- Some cases we use
std::ops::Fn
as input parameter- e.q.
_.findIndex(array, predicate, ...)
=>::find_index(..., predicate: fn(&Value) -> bool, ...)
- e.q.
- If return value is statistic, using primitive type instead Value
- e.q.
_.findIndex(...)
=>::find_index(...) -> isize
, return value should beisize
, notValue::Number
- e.q.
- Because there is no
undefined
type in json, so if original function returnundefined
, the ported fn should always return Value::Null
- If the input parameters are options, not data, using primitive type instead Value
- If the original function allows optional parameters:
- known amount, e.q.
_.get(object, path, [defaultValue])
, the ported version fn should be::get(object, path, defaultValue)
, optional should become required - infinity amount, e.q.
_.merge(object, [...sources])
, the ported version fn should be::merge(object, source)
, should only keep one, depends on how the function works, and no more optionals
- known amount, e.q.
- It might implement helper functions, e.q.:
fn
withx_
prefix: input is not Value- e.q.
x_capitalize(&str) -> Value
- e.q.
fn
with_x
suffix: output is not Value- e.q.
capitalize_x(Value) -> String
- e.q.
fn
with bothx_
and_x
- e.q.
x_capitalize_x(&str) -> &str
- e.q.
- If the function accept multiple types, we can only choose one to implement
- e.q.
_.merge({a:1}, {b:2})
,_.merge([1], [2])
=> ...
- e.q.
Examples:
section should be exactly same as the examples in lodash doc.- Test cases should all be written in the
More examples
section, we relied on powerful rust's doc test
Dev
# Up
# Lint
# Preview doc
# Bump version and push
Check lodash.js api
$ npm i
$ node
Welcome to Node.js v15.14.0.
Type ".help" for more information.
> const l = require('lodash')
undefined
> l.toString()
''
>