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

utility-framework

v1.0.5

Published

A modern node framework for conversion, formatting, parsing, validation, and more.

Downloads

13

Readme

Description

This library contains hundreds of utility methods such as converters, formatters, parsers, validators, etc. necessary for dealing with built-in JavaScript types such as Array, Blob, Date, Map, Number, Object, Set and String. The names of the abstract classes provided by this library are simply the plural form of the afore-mentioned types i. e. Arrays, Blobs, Dates, Maps, Numbers, Objects, Sets and Strings. These abstract classes are only composed of static members (utility methods). The motivation to build this library comes from the fact that often it becomes necessary to install several libraries e. g. one library for validations, another one for dealing with dates, another one for conversions, etc. This sometimes leads to serious performance issues on applications/libraries. utility-framework does not depend on other libraries, it has its own implementation of each and every utility provided. This enables the developers of this library to continuously refactor and improve the code inside it.

Installation

Execute the following command from your project directory:

npm install utility-framework

and then enjoy using it.

Usage

This library is simply composed of abstract classes which can be used as follows:

const {
  Arrays,
  Blobs,
  Dates,
  Maps,
  Numbers,
  Objects,
  Sets,
  Strings,
  Utils,
} = require('utility-framework');

// Arrays examples:
Arrays.addFirst(["b", "c"], "a"); // ["a", "b", "c"]
Arrays.first(["a", "b", "c"]); // "a"
Arrays.isNotEmpty(["a", "b", "c"]); // true
Arrays.isEmpty([]); // true
Arrays.has(["a", "b", "c"], "a"); // true
Arrays.last(["a", "b", "c"]); // "c"

// Blobs examples:
await Blobs.fromObjectURL('some/url');
Blobs.isBlob(new Blob());
await Blobs.toBase64(blob);
Blobs.toFile(blob);
await Blobs.toImageData(blob);
await Blobs.toObjectURL(blob);

// Chars examples:
Chars.isAlpha('E'); // true
Chars.isASCII('|'); // true
Chars.isASCIIControl(Chars.BS); // true
Chars.isDigit('9'); // true
Chars.isHinduDigit('१'); // true
Chars.isLetter('我'); // true
Chars.isLetterOrDigit('ぃ'); // true
Chars.isLowerCase('ы'); // true
Chars.isLowSurrogate('\uDFFF'); // true
Chars.isPersianDigit('۴'); // true
Chars.isSurrogatePair('\ud801\udbff', '\udc9f'); // false
Chars.isUpperCase('Б'); // true
Chars.isWhitespace('\t'); // true

// Dates examples:
Dates.isAfter(Dates.now, "2023-05-11T23:20:12");
Dates.addDays(Dates.now, 12);
Dates.parseISO("2023-05-11T23:20");
Dates.isBetween("2023-05-11", "2023-05-10", "2023-05-12");
Dates.daysDifference("2023-05-11", "2023-05-10");

// Maps examples:
Maps.isEmpty(new Map()); // true
Maps.isMap([[0, "a"], [1, "b"]]); // false
const map = new Map();
map.set("a", "abc");
map.set("b", false);
map.set("c", 123);
Maps.toObject(map);

// Numbers examples:
Numbers.abs(-1); // 1
Numbers.isInteger(1); // true
Numbers.isNatural(-123); // false
Numbers.isNotNumber(0/0); // true
Numbers.isNumber({}); // false
Numbers.isPrime(2); // true
Numbers.randomInt(1, 8);
Numbers.toString(123); // "123"

// Objects examples:
Objects.fromJson('{"a":2,"b":"abc"}'); // {a: 2, b: "abc"}
Objects.hasProperty({a: true, b: 'abc'}, 'a'); // true
Objects.isNotNull({}); // false
Objects.isObject({}); // true
Objects.omit({ a: !0 }, "a"); // {}
Objects.pick({ a: null, b: true }, "a");
Objects.toIterable({ a: 'abc', b: 444, c: true });
Objects.toJson({a: true}); // "{"a":true}"

// Sets examples:
Sets.isNotEmpty(new Set()); // false
Sets.isSet(undefined); // false
Sets.isWeakSet(new WeakSet()); // true
const set = new Set();
set.add("abc");
Sets.toMap(set);

// Strings examples:
Strings.isNullOrEmpty(""); // true
Strings.normalize("  Lorem  ipsum dolor sit "); // "Lorem ipsum dolor sit"
Strings.isNumerical("12.34"); // true
Strings.hasWhitespace("Lorem\t"); // true
Strings.countMatches("ho ho ho", "ho"); // 3
Strings.decode("2aMgaXMgMyBpbiBBcmFiaWM="); // "٣ is 3 in Arabic"
Strings.encode("\u0663 is 3 in Arabic"); // "2aMgaXMgMyBpbiBBcmFiaWM="
Strings.toTitleCase("jOhN doE"); // John Doe
Strings.toCharArray("🐑🐑🐑"); // ["🐑", "🐑", "🐑"]
Strings.repeat("abc", 5); // "abcabcabcabcabc"
Strings.remove("adefbc", "def"); // "abc"
Strings.reverse("😃😄😁😆🤣"); // "🤣😆😁😄😃"
Strings.toCamelCase("\nAbc  def"); // "abcDef"
Strings.toKebabCase("\nAbc  def"); // "abc-def"
Strings.upperFirst("john Doe"); // "John Doe"

// Utils examples:
Utils.isBoolean(false); // true
Utils.isDefined(false); // true
Utils.isError(new TypeError('abc')); // true
Utils.isFile(new File([], "abc")); // true
Utils.isFunction(() => {}); // true
Utils.isIterable(new Set()); // true
Utils.isNullOrUndefined(undefined); // true
Utils.isPrimitive("abc"); // true
Utils.isPromise(Promise.resolve()); // true
Utils.isUndefined(null); // false

Support

Something isn't working as expected in this library? Feel free to create a GitHub issue.

Contribution

Please contact me if you would like to contribute to utility-framework.

Roadmap

Latest stable: v1.0.5

License

Licensed under the MIT License.