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

@fujitsusweden/futile

v0.5.0

Published

Utility library

Downloads

23

Readme

Fujitsu Sweden Utils

What is it

A utility library, mainly used by other packages by Fujitsu Sweden.

Usage

const futile = require("@fujitsusweden/futile");

futile.canonize(value)

> futile.canonize({ c: { d: 1, a: 2 }, b: 3, e: 4 })
'{"b":3,"c":{"a":2,"d":1},"e":4}'

Like JSON.stringify except object keys are sorted. This serialization is JSON compatible, meaning that _.isEqual(a, JSON.parse(futile.canonize(a))) is always true, just like _.isEqual(a, JSON.parse(JSON.stringify(a))). It also provides a canonization, meaning that futile.canonize(a) === futile.canonize(b) if and only if _.isEqual(a, b). Note that JSON.stringify does not provide a canonization w.r.t. _.isEqual. For example, futile.canonize({ a:1, b:2 }) === futile.canonize({ b:2, a:1 }) but JSON.stringify({ a:1, b:2 }) !== JSON.stringify({ b:2, a:1 }). One use case for a canonizing serialization is property names for indexing on the contents of objects.

futile.deepFreeze(value)

Recursive variant of Object.freeze().

Example:

> o = deepFreeze({ a: { b: "ORIGINAL" }, c: 2 });
{ a: { b: "ORIGINAL" }, c: 2 };
> o.a.b = "changed";
"changed";
> o;
{ a: { b: "ORIGINAL" }, c: 2 };

Note that

  • The change to read-only properties is destructive, i.e. the argument to futile.deepFreeze is altered. If you want to keep a changeable version around, use _.cloneDeep first.
  • In strict mode, assigning to a read-only property as in the example above will throw an error.

futile.diffIntDiff(data1, data2)

A fast way to compute [_.differenceWith(data1, data2, _.isEqual), _.intersectionWith(data1, data2, _.isEqual), _.differenceWith(data2, data1, _.isEqual)].

In other words, given two lists of values, use the same definition of equality as _.isEqual and compute

  • A list of values only found in the first source list
  • A list of values found in both source lists
  • A list of values only found in the second source list

futile.err(message, object)

Makes it easier to pass meta-data in an error.

throw futile.err("Error message", { metadata1: value1, otherthing2: value2 })

futile.indexBy(collection, keyfun)

Given an array or other collection, return a plain object with values from the collection and keys calculated using keyfun. If keyfun is a string, it is treated as a function that returns the property by that name.

Example:

> const data = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
undefined
> futile.indexBy(data, 'name')
{ Alice: { id: 1, name: 'Alice' }, Bob: { id: 2, name: 'Bob' } }
> futile.indexBy(data, x => `_${x.id}`)
{ _1: { id: 1, name: 'Alice' }, _2: { id: 2, name: 'Bob' } }

futile.interval(intervalString)

Convert a temporal interval from a string representation to the number of milliseconds as an integer. Supported units are ms, s, min, h.

> futile.interval('5 s')
5000
> futile.interval('2 min')
120000

futile.now()

Returns a date object that represents now.

futile.reqMock(hint)

Return an object similar to an ExpressJS req object.

futile.since(date)

Returns the number of milliseconds between date and now.

futile.sleep(delay)

Asynchronous delay function. Accepts delay in milliseconds or in futile.interval format.

Example to wait 5 seconds:

await futile.sleep('5 s');

futile.xor(...args)

Returns true if an odd number of arguments are truthy, otherwise false.

Development

Run ./script without arguments for help