Gathering detailed insights and metrics for @github/issue-parser
Gathering detailed insights and metrics for @github/issue-parser
npm install @github/issue-parser
Typescript
Module System
Min. Node Version
Node Version
NPM Version
77.1
Supply Chain
99.5
Quality
89.1
Maintenance
100
Vulnerability
100
License
TypeScript (90.28%)
JavaScript (9.72%)
Total Downloads
607
Last Day
8
Last Week
83
Last Month
358
Last Year
607
8 Stars
36 Commits
3 Watching
2 Branches
3,885 Contributors
Latest Version
1.0.1
Package Id
@github/issue-parser@1.0.1
Unpacked Size
872.17 kB
Size
170.09 kB
File Count
72
NPM Version
10.8.3
Node Version
22.9.0
Publised On
16 Jan 2025
Cumulative downloads
Total Downloads
Last day
-86.2%
8
Compared to previous day
Last week
-57.4%
83
Compared to previous week
Last month
630.6%
358
Compared to previous month
Last year
0%
607
Compared to previous year
1
25
Convert issue form responses to JSON
This package can be used to parse GitHub issues into machine-readable JSON for processing. In particular, it is designed to work with issue forms to perform basic transformations on the issue body, resulting in a consistent JSON output.
Issues submitted using issue forms use a structured Markdown format. So long as the issue body is not heavily modified by the user, we can reliably parse the issue body into a JSON object.
1npm i @github/issue-parser
Here is a simple example of how to use this package in your project.
1import { parseIssue } from '@github/issue-parser' 2 3const issue = parseIssue('<issue body>', '<template>')
Assuming the issue and template look like these examples:
The resulting issue
object will look like the following:
1{ 2 name: 'this-thing', 3 nickname: 'thing', 4 color: ['blue'], 5 shape: ['square'], 6 sounds: ['re', 'mi'], 7 topics: [], 8 description: "This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!", 9 notes: '- Note\n- Another note\n- Lots of notes', 10 code: 'const thing = new Thing()\nthing.doThing()', 11 'code-string': 'thing.toString()', 12 'is-thing': { 13 selected: ['Yes'], 14 unselected: ['No'] 15 }, 16 'is-thing-useful': { 17 selected: ['Sometimes'], 18 unselected: ['Yes', 'No'] 19 }, 20 'read-team': 'IssueOps-Demo-Readers', 21 'write-team': 'IssueOps-Demo-Writers' 22}
parseIssue
This is the main function of the package. It takes two arguments:
issue: string
- The body of the issue to be parsedtemplate: string
- (Optional) The issue form template used to create the
issueoptions?: { slugify?: boolean }
- (Optional) Additional parsing options to
use when processing the issue bodyIf the template
value is provided, the package will attempt to transform the
issue response values into different types based on the type
property of the
specific field in the template. If the template
value is omitted, all parsed
values will be returned as strings. For information on the transformations that
are applied, see the Transformations section.
slugify: boolean
- If set to true
, any parsed keys that are not found in
the issue forms template (if provided) will be converted to
slugs using the
slugify package. Otherwise, the
original header value will be used as the object key.parseTemplate(template?: string)
Parses an issue form template and returns an object. This can be used to match form responses in the issue body with the fields, so that you can perform additional validation.
When parsing an issue and the associated form template, this package will attempt to match field IDs with response values. If a match is found, the field ID will be used in the parsed object keys (instead of the header value from the markdown response). If no match is found, the header text is used as the object key.
For example, if you have the following issue form template:
1name: Example Request 2description: Submit an example request 3title: '[Request] Example' 4 5body: 6 - type: input 7 id: name 8 attributes: 9 label: The Name of the Thing 10 description: The name of the thing you want to create. 11 placeholder: this-is-the-thing 12 validations: 13 required: true
And the following issue body:
1### The Name of the Thing 2 3this-thing 4 5### The Nickname of the Thing 6 7thing
The resulting parsed issue would be:
1{ 2 // Uses the ID value from the issue form template as the key 3 "name": "this-thing", 4 // Uses the original header value from the issue body 5 "The Nickname of the Thing": "thing" 6}
The following transformations will take place for responses, depending on the input type. The type is inferred from the issue form template. For information on each specific type, see Syntax for GitHub's form schema.
Before:
1This is a response
After (no change):
1This is a response
[!NOTE]
Empty lines are preserved in multiline responses.
Before:
1First line :D 2 3Third line!
After:
1First line :D\n\nThird line!
Before:
1red, blue, green
After:
1["red", "blue", "green"]
Before:
1- [x] Pick me! 2- [ ] Don't pick me D:
After:
1{ 2 "selected": ["Pick me!"], 3 "unselected": ["Don't pick me D:"] 4}
In the following situations, an input will be omitted from the output JSON:
Scenario | Example |
---|---|
Invalid Heading | ## This is invalid |
Empty Heading | ### |
This is a value | |
No Value | ### This is a heading |
### This is another | |
This is a value |
Normally, if a form is submitted with empty field(s), they will be included in the issue body as one of the following, depending on the input type in the form template.
Type | No Response |
---|---|
dropdown | None |
input | _No response_ |
textarea | _No response_ |
1### Dropdown Field 2 3None 4 5### Input or Textarea Field 6 7_No response_ 8 9### Checkboxes Field 10 11- [ ] Item A 12- [ ] Item B
These will be converted to one of the following, based on the type of input specified in the issue form template:
Type | Output |
---|---|
checkboxes | { "selected": [], "unselected": []} |
dropdown | [] |
input | undefined |
textarea | undefined |
No vulnerabilities found.
No security vulnerabilities found.