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() { asserteq!( capitalize!(json!("FRED")), json!("Fred") ); } ```
All implements should be same as lodash as possible
How?
fn
and macro
(for optional parameters usages)serde_json::Value
, except:
_.chunk(array, [size=1])
=> ::check!(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 json, so if original function return undefined
, the ported fn should always return Value::Null_.get(object, path, [defaultValue])
, the ported version fn should be ::get(object, path, defaultValue)
, optional should become required_.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 optionalsfn
with x_
prefix: input is not Valuex_capitalize(&str) -> Value
fn
with _x
suffix: output is not Valuecapitalize_x(Value) -> String
fn
with both x_
and _x
x_capitalize_x(&str) -> &str
_.merge({a:1}, {b:2})
, _.merge([1], [2])
=> ...Examples:
section should be exactly same as the examples in lodash doc.More examples
section, we relied on powerful rust's doc test```bash
cargo watch -x "test --features lazy_static" -w "Cargo.toml" -w "src"
./lint.sh
./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() ''
```