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
folderstringThe root folder to search for package.json files recursively.
packageNamestringThe 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
jsonOrPathstringEither a JSON string or a file path to a package.json file.
openInBrowserAction<string>An action that opens the given URL in a browser.
cdnProviderUrlstringThe base URL of the CDN provider (e.g. unpkg).
urlReplacementFunctionFunc<string, string, string>A function that constructs the final URL from the CDN provider URL and the package name.
Returns
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
jsonOrPathstringEither a JSON string or a file path to a package.json file.
Returns
Parse(string)
Parses a JSON string into a PackageJson object.
public static PackageJson Parse(string json)
Parameters
jsonstringThe JSON string to parse.
Returns
- PackageJson
The deserialized PackageJson object.