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

decorator-ord

v0.1.3

Published

Decorator for portation of haskell typeclass ord

Downloads

10

Readme

Decorator for portation of haskell typeclass ORD

The Ord Interface defines ordering in typescript. The decorator implements the Ordering-Interface. On the other hand it is a library for funtions. Mainly Lists of this interface are used.

There is an es5-translation in the dist-directory. tsc was used for transpiling.

As an addition there is a record-library to calculate some values by lists of IOrds. But it's experimental.

Installation

npm install decorator-ord --save

Usage

Decorator

  type TColor = "yellow" | "red";
  const carConfig = new OrdConfig();
  
  @Ord.implement({
      config: carConfig
  })
  class Car implements IEq {
    @Ord.field({
        ordinality: 2,
        dir:'DESC'
    })
    private age:number;
 
    @Ord.field({
        ordinality: 1,
        map: ['yellow','red']
    })
    private color:TColor;
    
    constructor(age:number, color:TColor){
        this.age=age;
        this.color=color;
    }
    
    //this is neccessary to ensure the interface
    greater:(a:IOrd)=>boolean;
    less:(a:IOrd)=>boolean;
    eq:(a:IEq)=>boolean;
    neq:(a:IEq)=>boolean;
  }

Notice the Configuration-Object. Objects of car can now be ordered by color and than by age. Be aware that the properties can be any type that support "<",">", are mapped or have IEq implemented.

Using the EQ-Library

sort(cs:IOrd[], config:IOrdConfig):IOrd[]

  sort(listOfCars, carConfig) //sorts listOfCars by carConfig

greater(cs:IOrd[], ref:IOrd, config:IOrdConfig):IOrd[]

  greater(listOfCars, new Car(null, 10), carConfig) //reveals all cars older than 10 years 
  greater(listOfCars, new Car('red', 10), carConfig) //reveals all red cars older than 10 years 

less(cs:IOrd[], ref:IOrd, config:IOrdConfig):IOrd[]

  less(listOfCars, new Car('red',null), carConfig) //reveals all yellow cars 
  less(listOfCars, new Car('red',5), carConfig) //reveals all yellow cars younger than 5 

Using EqConfig

clone():OrdConfig

  let copyOfConfig = carConfig.clone(); 

ordFields:Array

  let newFields:Array<IOrdField> = [];
  copyOfFields.ordFields.foreach((val, key) => if(key%2) newFields.push(val));
  copyOfFields.ordFields = newFields;

eqFields:Array

  let newFields:Array<EqField> = [];
  copyOfFields.eqFields.foreach((val, key) => if(key%2) newFields.push(val));
  copyOfFields.eqFields = newFields;

setOrdnialityOfField(name:string, fields:Array, newIndex = 0)

  let configCopy = carConfig.clone();
  configCopy.setOrdnialityOfField('age', configCopy.ordFields, 0);
  sort(listOfCars, configCopy) //Sorts cars with priority age

Using OrdAnd

fuzzyEq(cs:IEq[], refs:IEq[], config:IEqConfig):IEq[]

  @OrdAnd.implement({})
  export class CarAnd extends Car {
  }
  
  inRange(listOfCars, new CarAnd(10,'red'), new CarAnd(2,'yellow') 
  //reveals all red and yellow cars between 2 and 10 years.
  //all non-null properties must be fullfilled

Recorder

It's an experimental technique to extract field-information of lists of Ords. The role model is a recorder. The use is still a bit unclear to me. There are

  • CountRecord - frequency of values
  • BorderRecord - calculates min and max of values

Tests

npm test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

Release History

  • 0.1.0 Initial release
  • 0.1.1 decorator-eq as dependency
  • 0.1.2 better transpiling in dist/index.js used
  • 0.1.3 split config fields