Skip to content

Commit 8061c4d

Browse files
author
Alessio Michelini
committed
Update to TS 5
Updated dependencies Fixed linting errors
1 parent bc9b158 commit 8061c4d

File tree

7 files changed

+266
-302
lines changed

7 files changed

+266
-302
lines changed

package-lock.json

Lines changed: 220 additions & 252 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
"tslib": "^2.5.0"
1212
},
1313
"devDependencies": {
14-
"@babel/core": "^7.21.0",
15-
"@babel/preset-env": "^7.20.2",
14+
"@babel/core": "^7.21.4",
15+
"@babel/preset-env": "^7.21.4",
1616
"@istanbuljs/nyc-config-typescript": "^1.0.2",
17-
"@types/jest": "^29.4.0",
18-
"@types/node": "^18.15.0",
19-
"@typescript-eslint/eslint-plugin": "^5.54.1",
20-
"@typescript-eslint/parser": "^5.54.1",
17+
"@types/jest": "^29.5.0",
18+
"@types/node": "^18.15.11",
19+
"@typescript-eslint/eslint-plugin": "^5.57.1",
20+
"@typescript-eslint/parser": "^5.57.1",
2121
"auto-changelog": "^2.4.0",
2222
"babel-jest": "^29.5.0",
23-
"eslint": "^8.36.0",
23+
"eslint": "^8.37.0",
2424
"jest": "^29.5.0",
2525
"nyc": "^15.1.0",
26-
"ts-jest": "^29.0.5",
26+
"ts-jest": "^29.1.0",
2727
"ts-node": "^10.9.1",
28-
"typescript": "^4.9.5"
28+
"typescript": "^5.0.3"
2929
},
3030
"engines": {
3131
"node": ">=16.0.0"

src/lib/file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {VALID_FORMATS} from '../constants'
1+
import {VALID_FORMATS} from '../constants';
22

33
export const isFileValid = (file: string): boolean => {
4-
const regex = new RegExp(`(${VALID_FORMATS.join('|')})$`)
5-
return regex.test(file)
4+
const regex = new RegExp(`(${VALID_FORMATS.join('|')})$`);
5+
return regex.test(file);
66
}

src/lib/tags.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {INDEX_TAG} from '../constants'
1+
import {INDEX_TAG} from '../constants';
22

33
/**
44
* Tries to the first H2 title and adds the index tag right before it
55
* @param text The text to process
66
* @returns The updated text
77
*/
88
export const findFirstParagraph = (text: string): string => {
9-
const regex = /^(##\s.+)\n{1,3}/gm
10-
const split = text.split(regex)
11-
split.splice(1, 0, `<!-- ${INDEX_TAG}-start -->\n<!-- ${INDEX_TAG}-end -->\n\n`)
12-
return split.join('')
9+
const regex = /^(##\s.+)\n{1,3}/gm;
10+
const split = text.split(regex);
11+
split.splice(1, 0, `<!-- ${INDEX_TAG}-start -->\n<!-- ${INDEX_TAG}-end -->\n\n`);
12+
return split.join('');
1313
}
1414

1515
/**
@@ -21,23 +21,23 @@ export const findFirstParagraph = (text: string): string => {
2121
* @returns The parsed string
2222
*/
2323
export const replaceTag = (source: string, tag: string, content: string): string => {
24-
const start = `<!-- ${tag}-start -->`
25-
const end = `<!-- ${tag}-end -->`
26-
let tagStartPosition = source.indexOf(start)
27-
let tagEndPosition = source.indexOf(end)
24+
const start = `<!-- ${tag}-start -->`;
25+
const end = `<!-- ${tag}-end -->`;
26+
let tagStartPosition = source.indexOf(start);
27+
let tagEndPosition = source.indexOf(end);
2828
if (tagStartPosition === -1 || tagEndPosition === -1) {
2929
if (tag === INDEX_TAG) {
30-
source = findFirstParagraph(source)
31-
tagStartPosition = source.indexOf(start)
32-
tagEndPosition = source.indexOf(end)
30+
source = findFirstParagraph(source);
31+
tagStartPosition = source.indexOf(start);
32+
tagEndPosition = source.indexOf(end);
3333
} else {
34-
throw new Error(`You must add the ${tag} tags in the document!`)
34+
throw new Error(`You must add the ${tag} tags in the document!`);
3535
}
3636
}
3737

38-
const preTagContent = source.slice(0, tagStartPosition + start.length)
39-
const postTagContent = source.slice(tagEndPosition)
40-
return `${preTagContent}\n${content}\n${postTagContent}`
38+
const preTagContent = source.slice(0, tagStartPosition + start.length);
39+
const postTagContent = source.slice(tagEndPosition);
40+
return `${preTagContent}\n${content}\n${postTagContent}`;
4141
}
4242

4343
/**
@@ -48,6 +48,6 @@ export const replaceTag = (source: string, tag: string, content: string): string
4848
* @returns The replaced string
4949
*/
5050
export const replaceBlock = (source: string, block: string): string => {
51-
const regex = new RegExp(`${block}(.+?)${block}`, 'gms')
52-
return source.replace(regex, '')
51+
const regex = new RegExp(`${block}(.+?)${block}`, 'gms');
52+
return source.replace(regex, '');
5353
}

src/lib/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
*/
66

77
export function stringToPermalink(string: string): string {
8-
if (typeof string !== 'string') {
9-
return string
10-
}
11-
128
return string
139
.replace(/(-)+\1+/g, '')
1410
.replace(/\s/g, '-')

test/lib/tags.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {replaceTag, replaceBlock, findFirstParagraph} from '../../src/lib/tags'
1+
import {replaceTag, replaceBlock, findFirstParagraph} from '../../src/lib/tags';
22

33
describe('tags.ts', () => {
44
describe('findFirstParagraph (Function)', () => {
@@ -11,8 +11,8 @@ Some text\n`;
1111
const result = findFirstParagraph(mockContent)
1212
expect(result).toContain('<!-- index-start -->');
1313
expect(result).toContain('<!-- index-end -->');
14-
})
15-
})
14+
});
15+
});
1616

1717
describe('replacetag (Function)', () => {
1818
it('should replace the content', () => {
@@ -22,7 +22,7 @@ Some text\n`;
2222
Some test`;
2323
const result = replaceTag(mockContent, 'test', 'hello');
2424
expect(result).toContain('hello');
25-
})
25+
});
2626

2727
it('should throw an error if a tag is missing', () => {
2828
const mockContent = `# Some Title
@@ -35,8 +35,8 @@ Some text\n`;
3535
Some test`;
3636

3737
expect(() => replaceTag(mockContent2, 'test', 'hello')).toThrow();
38-
})
39-
})
38+
});
39+
});
4040

4141
describe('replaceBlock (Function)', () => {
4242
it('should remove the block from the content', () => {
@@ -47,7 +47,7 @@ Some text\n`;
4747
Some test`;
4848
const result = replaceBlock(mockContent, '```');
4949
expect(result).not.toContain('Find Me');
50-
})
50+
});
5151

5252
it('should not remove everything else', () => {
5353
const mockContent = `# Some Title
@@ -57,7 +57,7 @@ Some text\n`;
5757
Some test`;
5858
const result = replaceBlock(mockContent, '```');
5959
expect(result).toContain('Some test');
60-
})
60+
});
6161

6262
it('should remove every instance of the block from the content', () => {
6363
const mockContent = `# Some Title
@@ -71,6 +71,6 @@ Some text\n`;
7171
Some test`;
7272
const result = replaceBlock(mockContent, '```');
7373
expect(result).not.toContain('Find Me');
74-
})
75-
})
76-
})
74+
});
75+
});
76+
});

test/lib/utils.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ describe('Utils', () => {
44
describe('stringToPermalink', () => {
55
it('should return the url formatted string', () => {
66
expect(stringToPermalink('Hello world')).toEqual('hello-world');
7-
})
7+
});
88

99
it('should escape punctuation characters', () => {
1010
expect(stringToPermalink('Hello, world')).toEqual('hello-world');
1111
expect(stringToPermalink('Hello. World!')).toEqual('hello-world');
12-
})
12+
});
1313

1414
it('should escape special characters', () => {
1515
expect(stringToPermalink('Hello, @@--`world')).toEqual('hello-world');
1616
expect(stringToPermalink('Hello /world!****')).toEqual('hello-world');
1717
expect(stringToPermalink('---Hello---world---')).toEqual('helloworld');
18-
})
19-
})
20-
})
18+
});
19+
});
20+
});
2121

0 commit comments

Comments
 (0)