Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Decode JSON values into structured ReasonML and OCaml types. Inspired by Elm's Json.Decode and the Decode Pipeline, bs-decode
is an alternative to bs-json that focuses on structured, type-safe error handling, rather than exceptions. Additionally, bs-decode
collects up everything that went wrong while parsing the JSON, rather than failing on the first error.
Install via npm:
npm install --save bs-decode relude bs-abstract
Update your bsconfig.json
"bs-dependencies": [
"bs-decode"
],
The following is available to give you an idea of how the library works, but the complete documentation will probably be more useful if you want to write your own decoders.
// imagine you have a `user` type and `make` function to construct one
type user = {
name: string,
age: int,
isAdmin: bool,
lastLogin: option(Js.Date.t)
};
let make = (name, age, isAdmin, lastLogin) =>
{ name, age, isAdmin, lastLogin };
/**
* Given a JSON value that looks like:
* { "name": "Michael", "age": 32, "roles": ["admin"] }
*
* you can write a function to convert this JSON into a value of type `user`
*/
module Decode = Decode.AsResult.OfParseError; // module alias for brevity
let decode = json =>
Decode.Pipeline.(
succeed(make)
|> field("name", string)
|> field("age", intFromNumber)
|> field("roles", map(List.contains("admin"), list(string)))
|> optionalField("lastLogin", date)
|> run(json)
);
let myUser = decode(json); /* Ok({ name: "Michael", ...}) */
All contributions are welcome! This obviously includes code changes and documentation improvements (see CONTRIBUTING), but we also appreciate any feedback you want to provide (in the form of Github issues) about concepts that are confusing or poorly explained in the docs.
Released under the MIT license.
0.11.0 (Mar 31, 2020)
bs-abstract
peer-dependency is now bs-bastet
, and the required Relude version is 0.59+. See the Relude release notes and the Bastet migration guide for details.Decode
and prevent direct access to the Decode_*
modules via Bucklescript's public
flagokJson
is a decoder that always passes and preserves the input JSONFAQs
Type-safe JSON decoding for ReasonML and OCaml
The npm package bs-decode receives a total of 37 weekly downloads. As such, bs-decode popularity was classified as not popular.
We found that bs-decode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.