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

@spicypixel/core-kit-js

v0.0.59

Published

Spicy Pixel Core Kit JS

Downloads

56

Readme

Spicy Pixel Core Kit JS

What: This developer kit contains core modules for the Spicy Pixel JavaScript Framework, a foundation for building apps, libraries, and middleware.

Why: Some built-in APIs from Node.js and web browsers need a little love to be developer friendly and the base platforms have gaps that get filled by dozens of modules from different vendors. The goal of the Core Kit is to unify common dependencies under a modern framework.

How: The kit wraps key modules from Node.js and other dependencies into more modern interfaces that favor object-oriented design principles and newer language features like asynchronous promises.

The framework strives to provide abstractions that work in a variety of JavaScript environments, including web browsers and Node.js. In some cases, platform specific providers will specialize an interface to a given execution environment.

Features

  • File system libraries
  • Child process execution
  • OS details (platform, architecture, cpus, memory)
  • Data encoding (media type, data url, array buffer conversion)
  • Promise contracts that support async/await
  • TypeScript ambient declarations for strong types

Modules

array-buffer-converter

Convert array buffers to and from base64 and binary strings.

Sample

import { ArrayBufferConverter } from "@spicypixel/core-kit-js";

describe("ArrayBufferConverter", () => {
  it("should convert", () => {
    let testString = "Test";

    let arrayBuffer = ArrayBufferConverter.fromBinaryString(testString);
    arrayBuffer.byteLength.should.equal(4);

    let binaryString = ArrayBufferConverter.toBinaryString(arrayBuffer);
    binaryString.should.equal(testString);

    let base64 = ArrayBufferConverter.toBase64(arrayBuffer);
    base64.should.equal("VGVzdA==");

    let arrayBufferFromBase64 = ArrayBufferConverter.fromBase64(base64);
    equal(arrayBuffer, arrayBufferFromBase64).should.be.true;

    let decodedBase64 = ArrayBufferConverter.toBinaryString(arrayBufferFromBase64);
    decodedBase64.should.equal(testString);
  });
});

API

Standalone

export declare class ArrayBufferConverter {
    static toBase64(arrayBuffer: ArrayBuffer): string;
    static fromBase64(base64: string): ArrayBuffer;
    static toBinaryString(arrayBuffer: ArrayBuffer): string;
    static fromBinaryString(binary: string): ArrayBuffer;
}

Extensions

interface ArrayBufferConstructor {
  fromBase64(base64: string): ArrayBuffer;
  fromBinaryString(binaryString: string): ArrayBuffer;
}

interface ArrayBuffer {
  toBase64(): string;
  toBinaryString(): string;
}

child-process

The child process module provides a convenient way to spawn a process and wait for its completion.

Sample

static async doxygenAsync(): Promise<void> {
  await ChildProcess.spawnAsync("doxygen", [], { log: true });
}

API

export interface SpawnOptions extends NodeSpawnOptions {
    echo?: boolean;
    log?: boolean;
}

export default class ChildProcess {
    static spawnAsync(command: string, args?: string[], options?: SpawnOptions): Promise<NodeChildProcess>;
}

data-url

The data URL module makes it easy to create and consume Data URLs.

export default class DataURL {
    constructor(data: any, options?: any);
    mediaType: MediaType;
    isBase64: boolean;
    data: string;
    setBase64EncodedData(base64EncodedData: string): void;
    setURLEncodedData(urlEncodedData: string): void;
    toString(): string;
    toJSON(): string;
    valueOf(): string;
    toArrayBuffer(): ArrayBuffer;
    toBase64(): string;
    toBinaryString(): string;
    toUnicodeString(): string;
    static createFromBase64(base64: string, options?: any): DataURL;
    static createFromBinaryString(binary: string, options?: any): DataURL;
    static createFromUnicodeString(text: string, options?: any): DataURL;
}

file-system

The file system module wraps the Node.Js "fs" module in a more object-oriented way and adds support for globs (patterns), recrusive operations, and promises. Key types include File, Directory, FileSystemRecord, and the FileSystem module itself.

export declare enum FileSystemPermission {
    Visible,
    Read,
    Write,
    Execute,
}

export default class FileSystemRecord {
    static accessAsync(path: string, mode?: FileSystemPermission): Promise<void>;
    static chmodAsync(path: string, mode: string | number): Promise<void>;
    static chownAsync(path: string, uid: number, gid: number): Promise<void>;
}

export default class File extends FileSystemRecord {
    static copyAsync(src: string, dest: string): Promise<void>;
    static removeAsync(path: string): Promise<void>;
}

export default class Directory extends FileSystemRecord {
    static createAsync(path: string): Promise<void>;
    static createRecursiveAsync(path: string): Promise<void>;
    static copyAsync(src: string, dest: string): Promise<void>;
    static removeAsync(path: string): Promise<void>;
    static removeRecursiveAsync(path: string): Promise<void>;
}

export declare function copyPatternsAsync(
    sourcePatterns: string | string[], destination: string,
    options?: CopyPatternsOptions): Promise<void>;

export declare function removePatternsAsync(
    patterns: string | string[],
    options?: RemovePatternsOptions): Promise<string[]>;

export declare function removePatterns(
    patterns: string | string[],
    options?: RemovePatternsOptions): string[];

launch-arguments

The launch arguments module is a re-export of yargs which makes it easy to write console applications or access command-line arguments.

import { LaunchArguments } from "@spicypixel/core-kit-js";

// Command line option:
//  --fatal=[warning|error|off]
const fatal = LaunchArguments.argv.fatal;

media-type

The media type module is a convenient way to create and consume media type strings.

export default class MediaType {
    constructor(mediaType?: string);
    type: string;
    subtype: string;
    parameters: any;
    isValid: boolean;
    hasSuffix: boolean;
    isVendor: boolean;
    isPersonal: boolean;
    isExperimental: boolean;
    toString(): string;
    toJSON(): string;
    valueOf(): string;
}

operating-system

The operating system module provides an abstraction for obtaining information about the current platform and user. A default implementation wraps the built-in Node.js "os" module. Convenient enums are provided for common values.

Sample

import { OperatingSystemProvider, Architecture } from "@spicypixel/core-kit-js";

let os = OperatingSystemProvider.default;
if (os.architecture == Architecture.X64) {
  // do something special on x64
}

API

export declare enum Architecture {
    X64 = 0,
    IA32 = 1,
    ARM = 2,
    Other = 3,
}

export declare enum Platform {
    Darwin = 0,
    FreeBSD = 1,
    Linux = 2,
    SunOS = 3,
    Win32 = 4,
    Other = 5,
}

export declare enum Endianness {
    Big = 0,
    Little = 1,
}

export interface CpuDetails {
    model: string;
    speed: number;
    times: {
        user: number;
        nice: number;
        sys: number;
        idle: number;
        irq: number;
    };
}

export interface NetworkInterfaceDetails {
    address: string;
    netmask: string;
    family: string;
    mac: string;
    internal: boolean;
}

export interface UserDetails {
    username: string | Buffer;
    uid: number;
    gid: number;
    shell: string | Buffer;
    homedir: string | Buffer;
}

export interface UserOptions {
    encoding?: string;
}

export interface OperatingSystem {
    eol: string;
    architecture: Architecture;
    cpus: CpuDetails[];
    endianness: Endianness;
    freeMemory: number;
    homeDirectory: string;
    hostName: string;
    loadAverages: number[];
    networkInterfaces: {
        [index: string]: NetworkInterfaceDetails[];
    };
    platform: Platform;
    release: string;
    tempDirectory: string;
    totalMemory: number;
    uptimeSeconds: number;
    user: UserDetails;
    getUser(options?: UserOptions): UserDetails;
}

export declare class OperatingSystemProvider {
    static default: OperatingSystem;
}

promise

Promise is a re-export of bluebird.