Convert 12 JavaScript files to TypeScript (#57575)
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
import { schema } from '@/frame/lib/frontmatter'
|
||||
|
||||
// Copy the properties from the frontmatter schema.
|
||||
const featureVersions = {
|
||||
interface FeatureVersionsSchema {
|
||||
type: 'object'
|
||||
properties: {
|
||||
versions: Object.assign({}, schema.properties.versions),
|
||||
versions: any
|
||||
}
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
// Copy the properties from the frontmatter schema.
|
||||
const featureVersions: FeatureVersionsSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
versions: Object.assign({}, (schema.properties as any).versions),
|
||||
},
|
||||
additionalProperties: false,
|
||||
}
|
||||
|
||||
// Remove the feature versions properties.
|
||||
// We don't want to allow features within features! We just want pure versioning.
|
||||
delete featureVersions.properties.versions.properties.feature
|
||||
|
||||
// Call it invalid if any properties other than version properties are found.
|
||||
featureVersions.additionalProperties = false
|
||||
|
||||
// avoid ajv strict warning
|
||||
featureVersions.type = 'object'
|
||||
|
||||
export default featureVersions
|
||||
@@ -1,18 +0,0 @@
|
||||
export const term = {
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
pattern: '^((?!\\*).)*$', // no asterisks allowed
|
||||
}
|
||||
|
||||
export default {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['term'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
term,
|
||||
},
|
||||
},
|
||||
minItems: 21,
|
||||
}
|
||||
43
src/data-directory/lib/data-schemas/glossaries-candidates.ts
Normal file
43
src/data-directory/lib/data-schemas/glossaries-candidates.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export interface TermSchema {
|
||||
type: 'string'
|
||||
minLength: number
|
||||
pattern: string
|
||||
}
|
||||
|
||||
export const term: TermSchema = {
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
pattern: '^((?!\\*).)*$', // no asterisks allowed
|
||||
}
|
||||
|
||||
export interface GlossaryCandidateItem {
|
||||
term: string
|
||||
}
|
||||
|
||||
export interface GlossaryCandidatesSchema {
|
||||
type: 'array'
|
||||
items: {
|
||||
type: 'object'
|
||||
required: ['term']
|
||||
additionalProperties: false
|
||||
properties: {
|
||||
term: TermSchema
|
||||
}
|
||||
}
|
||||
minItems: number
|
||||
}
|
||||
|
||||
const schema: GlossaryCandidatesSchema = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['term'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
term,
|
||||
},
|
||||
},
|
||||
minItems: 21,
|
||||
}
|
||||
|
||||
export default schema
|
||||
@@ -1,18 +0,0 @@
|
||||
import { term } from './glossaries-candidates'
|
||||
|
||||
export default {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['term', 'description'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
term,
|
||||
description: {
|
||||
type: 'string',
|
||||
lintable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
minItems: 21,
|
||||
}
|
||||
44
src/data-directory/lib/data-schemas/glossaries-external.ts
Normal file
44
src/data-directory/lib/data-schemas/glossaries-external.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { term, type TermSchema } from './glossaries-candidates'
|
||||
|
||||
export interface GlossaryExternalItem {
|
||||
term: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface DescriptionSchema {
|
||||
type: 'string'
|
||||
lintable: boolean
|
||||
}
|
||||
|
||||
export interface GlossariesExternalSchema {
|
||||
type: 'array'
|
||||
items: {
|
||||
type: 'object'
|
||||
required: ['term', 'description']
|
||||
additionalProperties: false
|
||||
properties: {
|
||||
term: TermSchema
|
||||
description: DescriptionSchema
|
||||
}
|
||||
}
|
||||
minItems: number
|
||||
}
|
||||
|
||||
const schema: GlossariesExternalSchema = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['term', 'description'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
term,
|
||||
description: {
|
||||
type: 'string',
|
||||
lintable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
minItems: 21,
|
||||
}
|
||||
|
||||
export default schema
|
||||
@@ -3,15 +3,15 @@ import { describe, expect, test } from 'vitest'
|
||||
import filenameToKey from '@/data-directory/lib/filename-to-key'
|
||||
|
||||
describe('filename-to-key', () => {
|
||||
test('converts filenames to object keys', () => {
|
||||
test('converts filenames to object keys', (): void => {
|
||||
expect(filenameToKey('foo/bar/baz.txt')).toBe('foo.bar.baz')
|
||||
})
|
||||
|
||||
test('ignores leading slash on filenames', () => {
|
||||
test('ignores leading slash on filenames', (): void => {
|
||||
expect(filenameToKey('/foo/bar/baz.txt')).toBe('foo.bar.baz')
|
||||
})
|
||||
|
||||
test('supports MS Windows paths', () => {
|
||||
test('supports MS Windows paths', (): void => {
|
||||
expect(filenameToKey('path\\to\\file.txt')).toBe('path.to.file')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user