npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fra

v0.0.4

Published

Object model mapper written in TypeScript

Downloads

16

Readme

fra

npm

Small (<1Kb) mapping library built in TypeScript. This project is still in development so the api may change until a stable release.

about

The project was created to make object mapping easier in as simple a way as possible. This can help facilitate patterns such as a multi-tier architecture or DDD where you want to map between domain models and DTOs. However, this was created to solve a case where we need to map multiple legacy rest responses into one cleaner model to represent a GraphQL schema.

The name comes from Fra Mauro who, at the time (1400s) created the most detailed and accurate map of the world. There's a crater named after him on the moon that was inteded to be explored by Apollo 13. But really I just needed a name.

installation

npm i fra

usage

Fra will automatically map properties that are shared between both the source and target. You can chain the .field method to override a map or provide a map for a field that does not exist on the target.

import { Fra } from "fra";

class Person {
    firstName: string = "Patrick";
    lastName: string = "Dunn";
    getFullName(): string {
        return `${this.firstName} ${this.lastName}`;
    }
}

class PersonDTO {
    firstName: string = undefined;
    lastName: string = undefined;
    fullName: string = undefined;
}

const personMapper = Fra.createMap<Person, PersonDTO>(PersonDTO)
    .field("fullName", (source) => source.getFullName());

const person = new Person();
const personDTO = personMapper.map(person);

Fra

  • .field(fieldName, callback): allows you to specify a mapping function for a specific field.
  • .map(source, initialTarget?): map the source to the target with an optional initialTarget to hydrate. Default instatiates a new object for target.
  • .mapAll(sources): map many sources to many targets
  • createMap<Source, Target>(Target): create a mapper from a source to a target object. You can also just instatiate an instance of Fra directly. This is here just to help with creating a chain to register fields cleanly.

link

link(Target, mappers) returns a function that accepts an array of different sources that match the input mappers. You can call the returned function to execute each mapper in the array to create a single target object.

import { link } from "fra";

const multiPersonMapper = link(PersonDTO, [personMapper, humanMapper]);
const result = multiPersonMapper(person, human); // output is a PersonDTO mapped from both the human and person object

Updates

  • 0.0.3: Added link and .mapAll. Setup jest tests for source.