Skip to content

Commit

Permalink
Add strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 13, 2022
1 parent fa0df17 commit 72e87df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function toJson(value, options = {}) {
const comments = comment ? (Array.isArray(comment) ? comment : [comment]) : []
const delimiter = options.delimiter || ':'
const forgiving = options.forgiving
/** @type {Record<string, unknown>} */
const propertyOrValues = {}

const lines = value
Expand All @@ -46,6 +47,7 @@ export function toJson(value, options = {}) {
// Transform `value` to a property--value tuple.
function (value) {
const values = value.split(delimiter)
// @ts-expect-error: always one.
const result = [values.shift().trim()]

if (values.length > 0) {
Expand All @@ -56,7 +58,7 @@ export function toJson(value, options = {}) {
}
)

/** @type {boolean} */
/** @type {boolean|undefined} */
let isPropertyValuePair

for (const [index, line] of pairs.entries()) {
Expand Down Expand Up @@ -126,5 +128,6 @@ export function toJson(value, options = {}) {
* @param {Array<string>} b
*/
function sortOnFirstIndex(a, b) {
// @ts-expect-error: never empty
return a[0].codePointAt(0) - b[0].codePointAt(0)
}
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test('Invalid lists', function (t) {

t.test('should honour `log: false`', function (st) {
const stop = cept(console, 'log', hoist)
/** @type {Array<unknown>} */
/** @type {Array<unknown>|undefined} */
let parameters

toJson('unicorn\nrainbow\nunicorn', {forgiving: true, log: false})
Expand Down Expand Up @@ -229,7 +229,7 @@ test('Invalid objects', function (t) {

t.test('should honour `log: false`', function (st) {
const stop = cept(console, 'log', hoist)
/** @type {Array<unknown>} */
/** @type {Array<unknown>|undefined} */
let parameters

toJson('doge: so scare\nunicorn: magic creature\ndoge: so scare\n', {
Expand Down
18 changes: 10 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"include": ["*.js"],
"include": ["**/**.js"],
"exclude": ["coverage", "node_modules"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2020"],
"module": "node16",
"newLine": "lf",
"skipLibCheck": true,
"strict": true,
"target": "es2020"
}
}

0 comments on commit 72e87df

Please sign in to comment.