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

core-lang

v1.1.1

Published

Classes that should be in the core of the JavaScript language. Collections. Promises. Reflection. Working and tested from IE8+.

Downloads

3

Readme

core-lang

Classes that should be in the JavaScript language itself. The collections have a rich API to work with the data, full promises support, well written documentation and TypeScript definitions.

Usage

Available classes:

Collections

All collections inherit from XIterable. It returns an iterator and offers the classic Array methods of iteration, also filter, map/reduce, etc. with the same signature. In addition some methods are added (some of them inspired from groovy) to make chaining more easier (such as groupBy, transform, first or butFirst). Last but not least the collections have full Promises support, and allow processing of their content using the Promise API. For example, assuming that our collection contains promises, we can:

list([1,2,3,4])
    .map(Promise.resolve, Promise) // make them promises
    .mapPromise(function(it) {
        // mapPromise first resolves the items in the collection,
        // then it applies the mapping function
        // all the items are resolved at his stage, so we have the initial
        // array, being iterated over. We create new promises.
        return Promise.resolve(it * it);
    }).then(function(collection) {
        // not only the value before mapping gets resolved, but also
        // the result gets first Promise.resolved and only after
        // added back into the collection
        assert.equal([1,4,9,16], collection.asArray());
    });

Furthermore since the collections are written in TypeScript, the module embeds the .d.ts file, so you get full autocomplete and documentation support from the IDE (pictured Visual Studio Code)

Extras

format

formatis a very simple string formatting method that uses positional parameters in the spirit of .NET:

var format = require("core-lang/lib/stringUtils").format;
var text = format("{0} {1}!", "Hello", "World");
console.log(text); // will output 'Hello World!'

reflect

reflect, as its name implies, offers some utility methods that allow reflection operations on objects and functions. Here is a sample of reflect displaying its own API:

var reflect = require("core-lang/lib/reflect"),
    format = require("core-lang/lib/stringUtils").format;
// reflect displaying its own API
reflect.functions(reflect).forEach(function(method) {
    console.log(format("function {0}({1});",
        method.key,
        reflect.argumentNames(method.value)
            .join(", ")
        ));
});

This will output:

function functionName(f);
function functions(obj);
function argumentNames(f);
function create(clazz, args);
function invoke(f, args);

ChangeLog

  • v1.1.1 2015-09-15 Collections have the types correctly exported, and the Promise is the ES6 implementation.
  • v1.1.0 2015-09-10 Exported the reflect methods, and string format.
  • v1.0.1 2015-09-05 Added a bunch of mocha tests. (unit test)
  • v1.0.0 2015-08-31 Initial release.