json

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPackageIndexes

func ExtractPackageIndexes(pkgName, targetedVersion, content string) []int

ExtractPackageIndexes find where a package is defined in a json source file. It returns the block indexes along with name and version. It assumes:

  1. the package won't be declared twice in the same block
  2. the declaration will be shaped as "<package name>" : "<version or constraints>"

If no targeted version is passed, it will search for any version

You can see the regex in action here: https://regex101.com/r/zzrEAh/1 It matches the following: "@typescript-eslint/eslint-plugin": "^5.12.0", "test": "3"

The expected result of FindAllStringSubmatchIndex is a [6]int, with the following structure : - index 0/1 represents block start/end - index 2/3 represents name start/end - index 4/5 represents version start/end

func GetSectionOffset

func GetSectionOffset(sectionName string, content string) int

GetSectionOffset computes the start line of any section in the file. To see the regex in action, check out https://regex101.com/r/3EHqB8/1 (it uses the dependencies section as an example) It matches lines like this:

"dependencies": {

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL