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

typed-json-transform

v0.27.2

Published

_ like library written in typescript using templated generics where reasonable

Downloads

284

Readme

typed-json-transform Build Status Coverage Status

NPM

_ like library written in typescript using templated generics where reasonable

usage

import { map } from 'typed-json-transform';

const strings = ['apple', 'bannana'];
const lengths = map(strings, (str: string) => {
    return str.length;
})

'lengths' is typed as Array because map() is templated to return an array of types deduced by the map function

its value is as expected:

[ 5, 7 ]

this library is NOT a drop-in replacement for underscore ot lodash, however functions with similiar names should do the same thing.

documentation = index.d.ts:

declare module 'typed-json-transform' {
  /* 
  * Container Methods
  */

  interface SIO { [index: string]: any }
  function each<T>(iter: { [index: string]: T } | T[], fn: (val: T, index?: string | number, breakLoop?: () => void) => void): void
  function extend<T, U>(target: T & SIO, source: U & SIO): T & U
  function extendN<T>(target: T & SIO, ...sources: Array<SIO>): T
  function assign<A, B>(a: A, b: B): A & B
  function combine<A, B>(a: A, b: B): A & B
  function combineN<T>(retType: T, ...args: SIO[]): T
  function any(iterable: Array<any>, fn: Function): boolean
  function every<T>(iterable: any[], fn: Function): boolean
  function map<R, I>(iter: { [index: string]: I } | I[], fn: (val: I, index: any) => R): R[]
  function reduce<T, S>(input: Array<T>, fn: (input: T, memo: S) => S, base?: S): S
  function reduce<T, S>(input: { [index: string]: T }, fn: (input: T, memo: S) => S, base?: S): S
  function sum<T>(input: { [index: string]: T } | Array<T>, fn: (input: T) => number): number
  function greatestResult<T>(input: { [index: string]: T } | Array<T>, fn: (input: T) => number): number
  function sumIfEvery<T>(input: { [index: string]: T } | Array<T>, fn: (input: T) => number): number
  function geoSum<T>(input: { [index: string]: T } | Array<T>, fn: (input: T, memo: number) => number): number
  function union<T>(...args: T[][]): T[]
  function intersect<T>(...args: T[][]): T[]
  function difference<T>(a: T[], b: T[]): T[]
  function contains<T>(set: any[], match: T): boolean
  function containsAny<T>(set: any[], match: any[]): boolean
  function containsAll<T>(set: any[], match: any[]): boolean
  interface ComparisonOptions {
    [index: string]: boolean;
    strict: boolean;
  }
  function isEqual(actual: any, expected: any, opts?: ComparisonOptions): boolean
  function prune<T>(obj: T): T
  function plain<T>(obj: T): T
  function clone<T>(input: T): T
  function arrayify<T>(val: T | T[]): T[]
  function okmap<T>(iterable: Object | Array<any>, fn: (v: any, k: string) => { [index: string]: T }): { [index: string]: T }
  function stringify(value: any, replacer?: (number | string)[], space?: string | number): string

  /*
  * Keypath
  */
  namespace Keypath {
    interface Options extends SIO {
      allLevels?: boolean;
      diffArrays?: boolean;
    }
  }

  function setValueForKeyPath(value: any, keyPath: string, input: SIO): void
  function mergeValueAtKeypath(value: any, keyPath: string, obj: SIO): void
  function valueForKeyPath(keyPath: string, input: SIO): any
  function unsetKeyPath(keyPath: string, obj: SIO): boolean
  function keyPathContainsPath(keyPath: string, ignorePath: string): boolean
  function filteredKeyPaths(_keyPaths: string[], ignore?: string[]): string[]
  function keyPaths(obj: SIO, _options?: Keypath.Options, _stack?: string[], parent?: string): string[]
  function allKeyPaths(obj: SIO): string[]
  function flatObject(object: any, options?: { includeBranches?: boolean }): SIO

  /*
  * Diff / Mongo Method
  */

  namespace Mongo {
    interface Document extends SIO {
      _id: string;
    }

    interface Collection {
      findOne: Function;
      find: Function;
      update: Function;
    }

    interface UpdateOptions {
      collection?: Collection;
      get?: Function;
      set?: Function;
      ignore?: string[];
    }

    interface Modifier {
      $set?: SIO;
      $unset?: SIO;
    }
  }

  function forwardDiffToModifier(prev: SIO, doc: SIO, fieldsToIgnore?: string[]): Mongo.Modifier
  function shouldSet(val: any, prev: any): boolean
  function shouldUnset(val: any, prev: any): boolean
  function diffToModifier(prev: SIO, doc: SIO, fieldsToIgnore?: string[], pruneEmptyObjects?: boolean): Mongo.Modifier
  function modifierToObj(modifier: Mongo.Modifier): SIO
  function objToModifier(obj: SIO): Mongo.Modifier
  function apply<T>(dest: T, source: Mongo.Modifier): T
  function $set(dest: SIO, source: Mongo.Modifier): void
  function $addToSet<T>(dest: T[], src: T): T[]
  function $unset(dest: Object, source: Mongo.Modifier): void
  function update(doc: Mongo.Document, options: Mongo.UpdateOptions): Mongo.Modifier
  function mapModifierToKey(modifier: Mongo.Modifier, key: string): Mongo.Modifier

  /*
  * Check
  */

  function check(value: any, type: any): boolean
  function isNumeric(n: any): boolean
  function isArguments(object: any): boolean
  function isEmpty(input: { [index: string]: string }): boolean
  function isUndefinedOrNull(value: any): boolean
  /*
  * Cascade
  */

  function cascadeShallow<T>(tree: T, keywords: string[], selectors: string[]): T
  function cascade<T>(tree: T, keywords: string[], selectors: string[]): T
  function select(input: string[], cssString: string): boolean;

  /*
  Graph
  */

  class Graph<T> {
    [index: string]: any;

    addNode(node: string, data?: T): void;
    removeNode(node: string): void;
    hasNode(node: string): boolean;
    getNodeData(node: string): any;
    setNodeData(node: string, data?: T): void;
    addDependency(from: string, to: string): void;
    removeDependency(from: string, to: string): void;
    dependenciesOf(node: string, leavesOnly: boolean): any[];
    dependantsOf(node: string, leavesOnly: boolean): any[];
    overallOrder(leavesOnly: boolean): any[];
  }

  /*
  Optionally Linked Hash Maps
  */

  class OLHV<T> {
    require?: string;
    value: T
  }
  class OLHM<T> {
    [index: string]: OLHV<T>;
  }
  function map<T>(olhm: OLHM<T>, fn: (v: any, k?: string) => T): T[];
  function okmap<T>(olhm: OLHM<T>, fn: (v: any, k?: string) => OLHV<T> | T): OLHM<T>;
  function parseOLHM(object: any): OLHM<any>;
  function safeOLHM<T>(olhm: OLHM<T>): T[];

}