Skip to content

Presentation and transformation layer for data output in RESTful APIs.

License

Notifications You must be signed in to change notification settings

r37r0m0d3l/deno-vicis

Repository files navigation

Vicis

« Vicis 🧮 🦕 »

Presentation and transformation layer for data output in RESTful APIs.

•• Vicis Documentation •• JavaScript Repository •• Deno Repository ••

This is Deno analogue to these libraries: 🐘 Fractal for PHP, 💎 Roar for Ruby, 🍢 Marshmallow for Python.

Buy Me A Coffee Tests


💬 Tl;dr

Code:

import { Vicis } from "vicis";
const configuration = {
  cast: { _id: Vicis.INTEGER, registered: Vicis.FLAG },
  defaults: { confirmed: false },
  exclude: [/(?:password)/gi, /^(?:_)(?:_)?/],
  omit: ["createdAt", "updatedAt", "deletedAt"],
  rename: { _id: "id", email: "login" },
  replace: { url: null }
};
const model = {
  _id: "54759309034942804",
  email: "johnwick@gmail.com",
  userPassword: "36e80092ff7f1ed72903cda9409b9d2c",
  registered: "1",
  url: "example.com",
  createdAt: "2020-01-01 01:23:45",
  __v: 1
};
const serializer = new Vicis(configuration);
serializer.data(model);
console.log(serializer.getData());

Output:

{
  "confirmed": false,
  "id": 54759309034942804,
  "login": "johnwick@gmail.com",
  "registered": true,
  "url": null
}

⚙️Install

Import from URL

// From URL
import { Vicis } from "https://deno.land/x/vicis/mod.ts";
// Bundled from URL
import { Vicis } from "https://deno.land/x/vicis/vicis.bundle.js";

Import from "importmap.json"

{
  "imports": {
    "vicis": "https://deno.land/x/vicis/mod.ts"
  }
}
import { Vicis } from "vicis";
deno run --importmap=importmap.json --unstable your-script.js

🗺️ My other projects

Full list here