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

@carlos.anuarbe/2019-11-07

v1.0.0

Published

root

Downloads

3

Readme

Ejercicio 11-07

El ejercicio consiste en implementar una de estas abstracciones:

  • List
  • Tree
  • Maybe
  • Either

Fecha de entrega

El pull request para la entrega del ejercicio debe crearse antes del comienzo de la clase del jueves día 28 de noviembre.

Enunciado

Modifica el archivo index.js de cada carpeta para implementar una de las abstracciones propuestas, utilizando patrones diferentes en cada una de ellas:

  • class/: debe exponer una clase, creada con el keyword class.
  • factory/: debe exponer una función que pueda ser llamada sin new.
  • prototype/: debe exponer un constructor (implementado sin el keyword class).

Modifica el archivo package.json de cada carpeta como sea necesario y publica una librería en NPM a partir de cada uno de ellos. Los nombres de los paquetes deben tener un formato acorde a los ejemplos en los párrafos siguientes.

Podéis seguir la guía de NPM sobre cómo publicar un módulo: https://docs.npmjs.com/creating-and-publishing-scoped-public-packages . Tened en cuenta que necesitaréis instalar NPM como ejecutable y crea una cuenta cuyo nombre de usuario sea vuestro código en la asignatura (eg gerardo.munguia).

List

const { Cons, Nil } = require("@gerardo.munguia/list-class");

const food = new Cons("broccoli", new Cons("kale", new Nil()));

console.log(food.head); // -> broccoli
console.log(food.map(meal => `steamed ${meal}`)); // -> ("steamed broccoli", ("steamed kale", nil))
console.log(food.getType()); // -> List
console.log(new Nil().getType()); // -> List

Tree

const { Branch, Leaf } = require("@gerardo.munguia/tree-prototype");

const leftBranch = new Branch("foo", new Leaf(), new Leaf());
const rightBranch = new Branch("bar", new Leaf(), new Leaf());
const tree = new Branch("baz", leftBranch, rightBranch);

console.log(tree.left); // -> ("foo", 🍂, 🍂)
console.log(tree.map(word => `${word}!`)); // -> ("baz", ("foo!", 🍂, 🍂), ("bar!", 🍂, 🍂))
console.log(tree.getType()); // -> Tree
console.log(new Leaf().getType()); // -> Tree

Maybe

const { createJust, createNothing } = require("@gerardo.munguia/maybe-factory");

const prop = (key, object) =>
  key in object ? createJust(object[key]) : createNothing();

const httpPostMessage = { method: "POST", body: "foobar" };
const httpOptionMessage = { method: "POST" };

console.log(prop("foo", { foo: "bar" }).map(word => `${word}!`)); // -> Just("foo!")
console.log(prop("baz", { foo: "bar" }).map(word => `${word}!`)); // -> Nothing
console.log(prop("foo", { foo: "bar" }).getType()); // -> Maybe
console.log(prop("baz", { foo: "bar" }).getType()); // -> Maybe

Either

const { createLeft, createRight } = require("@gerardo.munguia/either-factory");

const prop = (key, object) =>
  key in object
    ? createRight(object[key])
    : createLeft(`Cannot read property '${key}'`);

const foobar = prop("foo", { foo: "bar" });
const bazbar = prop("baz", { foo: "bar" });

console.log(foobar.map(word => `${word}!`)); // -> Right("bar!")
console.log(bazbar.map(word => `${word}!`)); // -> Left("Cannot read property 'baz'")
foobar.runEither(error => console.error(new Error(error)), console.log); // -> foo
bazbar.runEither(error => console.error(new Error(error)), console.log); // -> Error: "Cannot read property 'baz'" at ...
console.log(prop("foo", { foo: "bar" }).getType()); // -> Either
console.log(prop("baz", { foo: "bar" }).getType()); // -> Either

Tecnologías

El ejercicio se debe realizar sin utilizar librerías externas.

Entregables

Todos los archivos de esta carpeta son entregrables.

El método de entrega será:

  • Un pull request a su rama master (/alumno/xxx.yyy/master). El PR puede hacerse desde un fork si es preciso.
  • Tres paquetes publicados en NPM, como se indica en el enunciado.

Preferiblemente, cread la rama para esta práctica a partir de la rama master del repositorio de la asignatura.