File tree 2 files changed +25
-12
lines changed
2 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,10 @@ describe(readUsageFromReadme, () => {
9
9
expect ( usage ) . toBeUndefined ( ) ;
10
10
} ) ;
11
11
12
- it ( "returns undefined when ## Usage found and ## Development is not found" , ( ) => {
12
+ it ( "returns existing content when ## Usage is found and a next important heading is not found" , ( ) => {
13
13
const usage = readUsageFromReadme ( "## Usage\n\nContents." ) ;
14
14
15
- expect ( usage ) . toBeUndefined ( ) ;
15
+ expect ( usage ) . toBe ( `\n\nContents.` ) ;
16
16
} ) ;
17
17
18
18
it ( "returns undefined when there is no content between ## Usage and ## Development" , ( ) => {
@@ -26,4 +26,20 @@ describe(readUsageFromReadme, () => {
26
26
27
27
expect ( usage ) . toBe ( "Content." ) ;
28
28
} ) ;
29
+
30
+ it ( "returns the content when content exists between ## Usage and ## Contributing" , ( ) => {
31
+ const usage = readUsageFromReadme (
32
+ "## Usage\n\n Content.\n## Contributing" ,
33
+ ) ;
34
+
35
+ expect ( usage ) . toBe ( "Content." ) ;
36
+ } ) ;
37
+
38
+ it ( "returns the content when content exists between ## Usage and ## Contributors" , ( ) => {
39
+ const usage = readUsageFromReadme (
40
+ "## Usage\n\n Content.\n## Contributors" ,
41
+ ) ;
42
+
43
+ expect ( usage ) . toBe ( "Content." ) ;
44
+ } ) ;
29
45
} ) ;
Original file line number Diff line number Diff line change 1
- const startDevelopment = "## Development" ;
2
1
const startUsage = "## Usage" ;
3
2
4
3
export function readUsageFromReadme ( readme : string ) {
@@ -7,17 +6,15 @@ export function readUsageFromReadme(readme: string) {
7
6
return undefined ;
8
7
}
9
8
10
- const indexOfDevelopment = readme . indexOf (
11
- startDevelopment ,
12
- indexOfUsage + startUsage . length ,
13
- ) ;
14
- if ( indexOfDevelopment === - 1 ) {
15
- return undefined ;
9
+ const offset = indexOfUsage + startUsage . length ;
10
+ const indexOfNextKnownHeading = readme
11
+ . slice ( offset )
12
+ . search ( / # # (?: D e v e l o p m e n t | C o n t r i b u t i n g | C o n t r i b u t o r s ) / ) ;
13
+ if ( indexOfNextKnownHeading === - 1 ) {
14
+ return readme . slice ( offset ) ;
16
15
}
17
16
18
- const usage = readme
19
- . slice ( indexOfUsage + startUsage . length , indexOfDevelopment )
20
- . trim ( ) ;
17
+ const usage = readme . slice ( offset , indexOfNextKnownHeading + offset ) . trim ( ) ;
21
18
22
19
return usage ? usage : undefined ;
23
20
}
You can’t perform that action at this time.
0 commit comments