JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 567
  • Score
    100M100P100Q95907F
  • License Apache-2.0

File system operations related utilities based on fs-extra

Package Exports

  • @handy-common-utils/fs-utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@handy-common-utils/fs-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

handy-common-utils

Handy utilities with type definitions

How to use

First add it as a dependency:

npm install handy-common-utils

Then you can use it in the code:

import { AwsUtils } from '../handy-common-utils/src';

const apig = new APIGateway();
const domainNameObjects = await AwsUtils.repeatFetchingItemsByPosition(
    pagingParam => apig.getDomainNames({limit: 500, ...pagingParam}).promise(),
);

API

handy-common-utils

Index

Classes

Interfaces

Type aliases

Variables

Type aliases

InParrellelResult

Ƭ InParrellelResult<T>: T extends void ? void : Array<T>

Type parameters:
Name
T

Variables

delayedReject

Const delayedReject: delayedReject = Utils.delayedReject


delayedResolve

Const delayedResolve: delayedResolve = Utils.delayedResolve


inParallel

Const inParallel: inParallel = Utils.inParallel


parseArn

Const parseArn: parseArn = AwsUtils.parseArn


repeat

Const repeat: repeat = Utils.repeat


repeatFetchingItemsByMarker

Const repeatFetchingItemsByMarker: repeatFetchingItemsByMarker = AwsUtils.repeatFetchingItemsByMarker


repeatFetchingItemsByNextToken

Const repeatFetchingItemsByNextToken: repeatFetchingItemsByNextToken = AwsUtils.repeatFetchingItemsByNextToken


repeatFetchingItemsByPosition

Const repeatFetchingItemsByPosition: repeatFetchingItemsByPosition = AwsUtils.repeatFetchingItemsByPosition


timeoutReject

Const timeoutReject: timeoutReject = Utils.timeoutReject


timeoutResolve

Const timeoutResolve: timeoutResolve = Utils.timeoutResolve

Classes

Class: AwsUtils

Hierarchy

  • AwsUtils

Index

Methods

Methods

parseArn

StaticparseArn(arn: string | null | undefined): ReturnType<*typeof* simpleParseArn> & { arn: string } | null | undefined

Parse ARN

Parameters:
Name Type Description
arn string | null | undefined the ARN string that could be null or undefined

Returns: ReturnType<*typeof* simpleParseArn> & { arn: string } | null | undefined

null or undeinfed if the input is null or undefined, or parsed ARN including the original ARN string


repeatFetchingItemsByMarker

StaticrepeatFetchingItemsByMarker<T>(itemsFieldName: string, fetchItemsByMarker: (parameter: { Marker?: undefined | string }) => Promise<{ NextMarker?: undefined | string }>): Promise<T[]>

Fetch items by Marker repeatedly. This function is useful for client side pagination when the response from AWS API contains NextMarker fields.

example const topics = await AwsUtils.repeatFetchingItemsByNextToken<SNS.Topic>('Topics', pagingParam => sns.listTopics({...pagingParam}).promise(), );

Type parameters:
Name Description
T type of the items returned by AWS API
Parameters:
Name Type Description
itemsFieldName string name of the field containing returned items in AWS API response
fetchItemsByMarker (parameter: { Marker?: undefined | string }) => Promise<{ NextMarker?: undefined | string }> the function for fetching items by Marker

Returns: Promise<T[]>

all items fetched


repeatFetchingItemsByNextToken

StaticrepeatFetchingItemsByNextToken<T>(itemsFieldName: string, fetchItemsByNextToken: (parameter: { NextToken?: undefined | string }) => Promise<{ NextToken?: undefined | string }>): Promise<T[]>

Fetch items by NextToken repeatedly. This function is useful for client side pagination when the response from AWS API contains NextToken fields.

example const topics = await AwsUtils.repeatFetchingItemsByNextToken<SNS.Topic>('Topics', pagingParam => sns.listTopics({...pagingParam}).promise(), );

Type parameters:
Name Description
T type of the items returned by AWS API
Parameters:
Name Type Description
itemsFieldName string name of the field containing returned items in AWS API response
fetchItemsByNextToken (parameter: { NextToken?: undefined | string }) => Promise<{ NextToken?: undefined | string }> the function for fetching items by NextToken

Returns: Promise<T[]>

all items fetched


repeatFetchingItemsByPosition

StaticrepeatFetchingItemsByPosition<T>(fetchItemsByPosition: (parameter: { position?: undefined | string }) => Promise<{ items?: Array<T> ; position?: undefined | string }>): Promise<T[]>

Fetch items by position repeatedly. This function is useful for client side pagination when the response from AWS API contains position and items fields.

example const domainNameObjects = await AwsUtils.repeatFetchingItemsByPosition( pagingParam => apig.getDomainNames({limit: 500, ...pagingParam}).promise(), );

Type parameters:
Name Description
T type of the items returned by AWS API
Parameters:
Name Type Description
fetchItemsByPosition (parameter: { position?: undefined | string }) => Promise<{ items?: Array<T> ; position?: undefined | string }> the function for fetching items by position

Returns: Promise<T[]>

all items fetched

Class: OclifUtils

Hierarchy

  • OclifUtils

Index

Methods

Methods

generateHelpText

StaticgenerateHelpText(commandInstance: Command, opts?: Partial<HelpOptions>): string

Generate formatted text content of help to a command

Parameters:
Name Type Description
commandInstance Command instance of the Command
opts? Partial<HelpOptions> format options

Returns: string


getCommandConfig

StaticgetCommandConfig(commandInstance: Command): Command

Parameters:
Name Type
commandInstance Command

Returns: Command


injectHelpTextIntoReadmeMd

StaticinjectHelpTextIntoReadmeMd(commandInstance: Command, opts?: Partial<HelpOptions>): Promise<void>

Parameters:
Name Type
commandInstance Command
opts? Partial<HelpOptions>

Returns: Promise<void>


prependCliToExamples

StaticprependCliToExamples(commandInstance: Command): void

Use this function to prepend command line to examples. This function needs to be called from init() function of the Command.

Parameters:
Name Type Description
commandInstance Command instance of the Command

Returns: void

Class: SingleCommandHelp

Hierarchy

  • Help

    SingleCommandHelp

Index

Constructors
Properties
Accessors
Methods

Constructors

constructor

+ new SingleCommandHelp(commandInstance: Command, opts?: Partial<HelpOptions>): SingleCommandHelp

Overrides void

Parameters:
Name Type
commandInstance Command
opts? Partial<HelpOptions>

Returns: SingleCommandHelp

Properties

commandInstance

Protected commandInstance: Command


config

Protected config: IConfig

Inherited from SingleCommandHelp.config


opts

Protected opts: HelpOptions

Inherited from SingleCommandHelp.opts


render

render: (input: string) => string

Inherited from SingleCommandHelp.render

Accessors

sortedCommands

Protectedget sortedCommands(): Plugin[]

Inherited from SingleCommandHelp.sortedCommands

Returns: Plugin[]


sortedTopics

Protectedget sortedTopics(): Topic[]

Inherited from SingleCommandHelp.sortedTopics

Returns: Topic[]

Methods

command

Protectedcommand(command: Command): string

Inherited from SingleCommandHelp.command

deprecated used for readme generation

Parameters:
Name Type Description
command Command The command to generate readme help for

Returns: string

the readme help string for the given command


formatCommand

ProtectedformatCommand(command: Command): string

Inherited from SingleCommandHelp.formatCommand

Parameters:
Name Type
command Command

Returns: string


formatCommands

ProtectedformatCommands(commands: Command[]): string

Inherited from SingleCommandHelp.formatCommands

Parameters:
Name Type
commands Command[]

Returns: string


formatRoot

ProtectedformatRoot(): string

Inherited from SingleCommandHelp.formatRoot

Returns: string


formatTopic

ProtectedformatTopic(topic: Topic): string

Inherited from SingleCommandHelp.formatTopic

Parameters:
Name Type
topic Topic

Returns: string


formatTopics

ProtectedformatTopics(topics: Topic[]): string

Inherited from SingleCommandHelp.formatTopics

Parameters:
Name Type
topics Topic[]

Returns: string


generateHelpText

generateHelpText(): string

Returns: string


showCommandHelp

showCommandHelp(command: Command): void

Inherited from SingleCommandHelp.showCommandHelp

Overrides void

Parameters:
Name Type
command Command

Returns: void


showHelp

showHelp(argv: string[]): void

Inherited from SingleCommandHelp.showHelp

Overrides void

Parameters:
Name Type
argv string[]

Returns: void


showRootHelp

ProtectedshowRootHelp(): void

Inherited from SingleCommandHelp.showRootHelp

Returns: void


showTopicHelp

ProtectedshowTopicHelp(topic: Topic): void

Inherited from SingleCommandHelp.showTopicHelp

Parameters:
Name Type
topic Topic

Returns: void

Class: Utils

Hierarchy

  • Utils

Index

Methods

Methods

delayedReject

StaticdelayedReject<T>(ms: number, reason: any): Promise<T>

Create a Promise that rejects after number of milliseconds specified

Type parameters:
Name Default
T never
Parameters:
Name Type Description
ms number number of milliseconds after which the created Promise would reject
reason any the reason of the rejection for the Promise

Returns: Promise<T>

the new Promise created


delayedResolve

StaticdelayedResolve<T>(ms: number, result?: T | PromiseLike<T> | undefined): Promise<T>

Create a Promise that resolves after number of milliseconds specified

Type parameters:
Name
T
Parameters:
Name Type Description
ms number number of milliseconds after which the created Promise would resolve
result? T | PromiseLike<T> | undefined the result to be resolved for the Promise

Returns: Promise<T>

the new Promise created


inParallel

StaticinParallel<Data, Result>(parallelism: number, jobs: Iterable<Data>, operation: (job: Data, index: number) => Promise<Result>): Promise<InParrellelResult<Result>>

Run multiple jobs/operations in parallel.

example const topicArns = topics.map(topic => topic.TopicArn!); await Utils.inParallel(5, topicArns, async topicArn => { const topicAttributes = (await sns.getTopicAttributes({ TopicArn: topicArn }).promise()).Attributes!; const topicDetails = { ...topicAttributes, subscriptions: [] } as any; if (this.shouldInclude(topicArn)) { inventory.snsTopicsByArn.set(topicArn, topicDetails); } });

Type parameters:
Name Description
Data Type of the job data, usually it would be an Array
Result Type of the return value of the operation function
Parameters:
Name Type Description
parallelism number how many jobs/operations can be running at the same time
jobs Iterable<Data> job data which will be the input to operation function. This function is safe when there are infinite unknown number of elements in the job data.
operation (job: Data, index: number) => Promise<Result> the function that turns job data into result asynchronously

Returns: Promise<InParrellelResult<Result>>

Promise of void if the operation function does not return a value, or promise of an arry containing results returned from the operation function.


repeat

Staticrepeat<Result, Param, Collection>(operation: (parameter: Partial<Param>) => Promise<Result>, nextParameter: (response: Result) => Partial<Param> | null, collect: (collection: Collection, result: Result) => Collection, initialCollection: Collection, initialParameter?: Partial<Param>): Promise<Collection>

Do an operation repeatedly and collect all the results. This function is useful for client side pagination.

example const domainNameObjects = await Utils.repeat( pagingParam => apig.getDomainNames({limit: 500, ...pagingParam}).promise(), esponse => response.position? {position: response.position} : null, (collection, response) => collection.concat(response.items!), [] as APIGateway.DomainName[], );

Type parameters:
Name Description
Result type of the operation result
Param type of the input to the operation, normally the input is a paging parameter
Collection type of the returned value of this function
Parameters:
Name Type Default value Description
operation (parameter: Partial<Param>) => Promise<Result> - a function that takes paging parameter as input and outputs a result, normally the operation supports paging
nextParameter (response: Result) => Partial<Param> | null - The function for calculating next parameter from the operation result. Normally the parameter controls paging, This function should return null when next invocation of the operation function is not desired.
collect (collection: Collection, result: Result) => Collection - the function for merging operation result into the collection
initialCollection Collection - initial collection which would be the first argument passed into the first invocation of the collect function
initialParameter Partial<Param> {} the parameter for the first operation

Returns: Promise<Collection>

Promise of collection of all the results returned by the operation function


timeoutReject

StatictimeoutReject<T>(operation: Promise<T>, ms: number, rejectReason: any): Promise<T>

Apply timeout to an operation, in case timeout happens, reject with the reason specified. If timeout does not happen, the resolved result or rejection reason of the original operation would be returned.

Type parameters:
Name
T
Parameters:
Name Type Description
operation Promise<T> the original operation that timeout would be applied
ms number number of milliseconds for the timeout
rejectReason any the reason of the rejection in case timeout happens

Returns: Promise<T>


timeoutResolve

StatictimeoutResolve<T>(operation: Promise<T>, ms: number, result?: T | PromiseLike<T> | undefined): Promise<T>

Apply timeout to an operation, in case timeout happens, resolve to the result specified. If timeout does not happen, the resolved result or rejection reason of the original operation would be returned.

Type parameters:
Name
T
Parameters:
Name Type Description
operation Promise<T> the original operation that timeout would be applied
ms number number of milliseconds for the timeout
result? T | PromiseLike<T> | undefined the result to be resolved in case timeout happens

Returns: Promise<T>

Interfaces

Interface: OclifHelpContent

Hierarchy

  • OclifHelpContent

Index

Properties

Properties

aliases

Optional aliases: undefined | string


args

Optional args: undefined | string


description

Optional description: undefined | string


examples

Optional examples: undefined | string


flags

Optional flags: undefined | string


usage

Optional usage: undefined | string