serde_json::Value with lodash.js spec, makes life easier.
Cargo.toml
toml
[dependencies]
serde_json_lodash = "0.1"
main.rs
```rust
use serdejson::json; fn main() { // macro style, optional parameters asserteq!( merge!(json!({'a':1}), json!({'b':2}), json!({'c':3})), json!({'a': 1, 'b': 2, 'c': 3}) );
// fn style, fixed parameters use serdejsonlodash::merge; assert_eq!( merge(json!({'a':1}), json!({'b':2})), json!({'a': 1, 'b': 2}) );
// x_
, _x
helpers for simple types
asserteq!(capitalize!(json!("FRED")), json!("Fred"));
asserteq!(xcapitalize!("FRED"), json!("Fred"));
asserteq!(capitalizex!(json!("FRED")), "Fred".toowned());
asserteq!(xcapitalizex!("FRED"), "Fred".toowned());
}
```
All implements should be same as lodash as possible
How?
fn
and macro
serde_json::Value
, excepts:
_.chunk(array, [size=1])
=> ::chunk(json!([1,2,3]), 2)
, size should be usize
, not Value::Number
std::ops::Fn
as input parameter
_.findIndex(array, predicate, ...)
=> ::find_index(..., predicate: fn(&Value) -> bool, ...)
_.findIndex(...)
=> ::find_index(...) -> isize
, return value should be isize
, not Value::Number
undefined
type in serde_json, so if the original function return undefined
, the ported version should return Value::Null_.get(object, path, [defaultValue])
=> ::get(object, path, defaultValue)
_.merge(object, [...sources])
=> ::merge(object, source)
, but macro could ::merge!(object, source1, source2, ...)
x_
prefix: input is not Value, will be downgrade typex_capitalize(&str) -> Value
_x
suffix: output is not Value, will be downgrade typecapitalize_x(Value) -> String
x_
and _x
x_capitalize_x(&str) -> &str
, x_add_x(n: Number, n2: Number) -> Number
_.toString([1,2])
, _.toString(123)
=> ::x_to_string(v: &str) -> Value
Examples:
section should be exactly same as the examples in lodash doc.More examples
section, we relied on powerful rust's doc test```bash
./dev.sh
./dev.sh --doc set
./lint.sh
cargo doc --open
./bump_push.sh ```
Check lodash.js api
```console $ npm i $ node Welcome to Node.js v15.14.0. Type ".help" for more information.
const l = require('lodash') undefined l.toString() ''
```