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

my-ts

v1.10.0

Published

fluent API for TypeScript

Downloads

5

Readme

my-ts

fluent syntax for writing TypeScript Apps

travis build npm devDependency Status dependency Status Commitizen friendly semantic-release codecov Known Vulnerabilities Code Climate Issue Count styled with prettier Quality Gate

npm badge

Installation

npm install my-ts --save

Examples

const object: any = ...
if (my(object).isNullOrUndefinedOrEmpty) {
    //code omitted for brevity
}

const validator = (element: any): IValidationResult => { ... }
const {isValid, validationErrors} = my(object).validateWith(validator);
if (isValid ) {
    //code omitted for brevity
}

const notNull = (element: any): boolean => { ... }
if (my(object).is(notNull)) {
    //code omitted for brevity
}

const elements: any[] = ...
const elementWithSpecificPattern = (element: any): boolean => { ... }
if (my(elements).hasAtLeastOne(elementWithSpecificPattern)) {
    //code omitted for brevity
}

const object: any = ...
const process = (element: any): any => { ... }
const {hasFailed, hasSucceeded, result, error} = my(object).tryTo(process);       
if (hasSucceeded) {
    //code omitted for brevity
}

const elements: any[] = ...
const closed = (element: any): boolean => { ... }
if (my(elements).areAll(closed)) {
    //code omitted for brevity
}

const textFileContent: string = ...
const lines = my(textFileContent).splitToLines();

API

    /**
     * Check if input object is null
     */
    isNull: boolean;

    /**
     * Check if input object is undefined
     */
    isUndefined: boolean;

    /**
     * Check if input object is null or undefined
     */
    isNullOrUndefined: boolean;

    /**
     * Check if input object is empty
     */
    isEmpty: boolean;

    /**
     * Check if input object has owned properties
     */
    hasOwnProperties: boolean;

    /**
     * Check if input object is null or undefined or empty
     */
    isNullOrUndefinedOrEmpty: boolean;

    /**
     * Check if input array contains a value
     */
    contains<T>(value: T): boolean;

    /**
     * Get in input array the first element that matches the predicate
     * @param {function} - Predicate used to find the element
     * @returns {T | undefined}
     */
    firstOrDefault<T>(predicate: (element: T, index: number) => boolean): T | undefined;

    /**
     * Select, in a new array, all items of the input array that satisfies the predicate.
     * @param {function} predicate - Predicate used to select the elements in input array
     * @returns {T[]} - returns the selected items or an empty array if no item is selected
     */
    where<T>(predicate: (element: T, index: number) => boolean): T[];

    /**
     * Validate input object with specified validator.
     * @param {function} validator - function that takes input object and returns an IValidationResult object
     * @returns {IValidationResult} - returns the IValidationResult object returned by the validator
     */
    validateWith<T>(validator: (element: T) => IValidationResult): IValidationResult;

    /**
     * Check if input object matches the predicate
     * @param {function} predicate - Predicate used to verify that input object satisfies a specific condition
     * @returns {boolean | undefined}
     */
    is<T>(predicate: (element: T) => boolean): boolean | undefined;

    /**
     * Check if input object does not match the predicate
     * @param {function} predicate - Predicate used to verify that input object does not satisfy a specific condition
     * @returns {boolean | undefined}
     */
    isNot<T>(predicate: (element: T) => boolean): boolean | undefined;

    /**
     * Check if input array contains at least one element that satisfies the predicate
     * @param {function} predicate - Predicate used to find an element
     * @returns {boolean | undefined} - returns true if one element has been found.
     *                                  returns undefined if the predicate throws an exception
     */
    hasAtLeastOne<T>(predicate: (element: T) => boolean): boolean | undefined;

    /**
     * Try to execute an action on input element
     * @param {function} action - Action used to process the element
     * @returns {IActionResult<U>} - returns an IActionResult object that wraps the result returned by the action.
     */
    tryTo<T, U>(action: (element: T) => U): IActionResult<U>;

    /**
     * Check if all items of the input array satisfies the predicate.
     * @param {function} predicate - Predicate used to check each item in the input array
     * @returns {boolean | undefined} - returns true when the predicate returns true for all items.
     *                                  returns undefined if the predicate throws an error
     */
    areAll<T>(predicate: (element: T) => boolean): boolean | undefined;

    /**
     * Extract all lines from the input string.
     * @returns {string[]} - by default every line in the result is trimmed and empty lines are removed}
     */
    splitToLines(): string[];