Table of Contents

Class PackageJsonHelper

Namespace
SunamoPackageJson
Assembly
SunamoPackageJson.dll

Provides utility methods for parsing and processing package.json files.

public class PackageJsonHelper
Inheritance
PackageJsonHelper
Inherited Members
Extension Methods

Methods

CategorizeByFirstNumberOfPackage(string, string)

Categorizes package.json files found in the specified folder by the major version number of the given package. Files where the package is not found are categorized under key -1. Files with "latest" version are categorized under MaxValue.

public static Task<Dictionary<int, List<string>>> CategorizeByFirstNumberOfPackage(string folder, string packageName)

Parameters

folder string

The root folder to search for package.json files recursively.

packageName string

The name of the package whose version is used for categorization.

Returns

Task<Dictionary<int, List<string>>>

A dictionary mapping major version numbers to lists of package.json file paths.

OpenPackagesFromPackageJsonFromNpm(string, Action<string>, string, Func<string, string, string>)

Opens all dependency packages from a package.json file in a browser using the specified CDN provider.

public static Task OpenPackagesFromPackageJsonFromNpm(string jsonOrPath, Action<string> openInBrowser, string cdnProviderUrl, Func<string, string, string> urlReplacementFunction)

Parameters

jsonOrPath string

Either a JSON string or a file path to a package.json file.

openInBrowser Action<string>

An action that opens the given URL in a browser.

cdnProviderUrl string

The base URL of the CDN provider (e.g. unpkg).

urlReplacementFunction Func<string, string, string>

A function that constructs the final URL from the CDN provider URL and the package name.

Returns

Task

PackageNamesFromPackageJson(string)

Extracts all package names from a package.json file or JSON string and returns them as npm URLs.

public static Task<List<string>> PackageNamesFromPackageJson(string jsonOrPath)

Parameters

jsonOrPath string

Either a JSON string or a file path to a package.json file.

Returns

Task<List<string>>

A list of npm package URLs for all dependencies and devDependencies.

Parse(string)

Parses a JSON string into a PackageJson object.

public static PackageJson Parse(string json)

Parameters

json string

The JSON string to parse.

Returns

PackageJson

The deserialized PackageJson object.