diff --git a/README.md b/README.md index ed5213a..81a50b3 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,23 @@ console.log(languageData.prismTag); // python console.log(languageData.logo); // https://user-images.githubusercontent.com/54644599/227718034-fe84d827-4f53-4466-b37a-2cdd3e817ba2.png ``` +```js +// Import the `getLanguageData` function from the `get-language-data` package. +import { getLanguageData } from 'get-language-data'; + +// Call the `getLanguageData` function with the language name, or, file extension. +const languageData = getLanguageData({ + prismTag: 'csharp', +})[0]; + +// // Use the `languageData` object to get the language data. +console.log(languageData.name); // C# +console.log(languageData.fileExtension[0]); // cs +console.log(languageData.namingConvention); // PascalCase +console.log(languageData.prismTag); // csharp +console.log(languageData.logo); // https://user-images.githubusercontent.com/54644599/227718064-c9b9f17a-6f55-4955-85ba-19e2c0420751.png +``` + ### `renameFile` ```js diff --git a/lib/getLanguageData/index.d.ts b/lib/getLanguageData/index.d.ts index a90f7a7..fe6666e 100644 --- a/lib/getLanguageData/index.d.ts +++ b/lib/getLanguageData/index.d.ts @@ -1,2 +1,2 @@ import type { LanguageDataType, GetLanguageDataInputType } from '../type'; -export default function getLanguageData({ name, fileExtension }: GetLanguageDataInputType): LanguageDataType[]; +export default function getLanguageData({ name, fileExtension, prismTag, }: GetLanguageDataInputType): LanguageDataType[]; diff --git a/lib/getLanguageData/index.js b/lib/getLanguageData/index.js index 6a02a0d..48842e8 100644 --- a/lib/getLanguageData/index.js +++ b/lib/getLanguageData/index.js @@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); var data_1 = __importDefault(require("../data")); function getLanguageData(_a) { - var name = _a.name, fileExtension = _a.fileExtension; + var name = _a.name, fileExtension = _a.fileExtension, prismTag = _a.prismTag; var language = data_1.default.filter(function (languageData) { if (name) { return languageData.name.toLowerCase() === name.toLowerCase(); @@ -16,6 +16,9 @@ function getLanguageData(_a) { } return languageData.fileExtension.includes(fileExtension); } + else if (prismTag) { + return languageData.prismTag === prismTag; + } }); if (language) { return language; diff --git a/lib/type.d.ts b/lib/type.d.ts index e5833d1..ed844f3 100644 --- a/lib/type.d.ts +++ b/lib/type.d.ts @@ -8,6 +8,7 @@ export type LanguageDataType = { export type GetLanguageDataInputType = { name?: string; fileExtension?: string; + prismTag?: string; }; export type RenameFileInputType = { name?: string; diff --git a/src/getLanguageData/__test__/test.ts b/src/getLanguageData/__test__/test.ts index 6c66180..fb3bdaa 100644 --- a/src/getLanguageData/__test__/test.ts +++ b/src/getLanguageData/__test__/test.ts @@ -12,6 +12,10 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('c')), ); }); + + it('should return C data based on prism tag "c"', () => { + expect(getLanguageData({ prismTag: 'c' })).toEqual(LanguageData.filter((language) => language.prismTag === 'c')); + }); // Test case for "C" ends here... // Test case for "C#" @@ -24,6 +28,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('cs')), ); }); + + it('should return C# data based on prism tag "csharp"', () => { + expect(getLanguageData({ prismTag: 'csharp' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'csharp'), + ); + }); // Test case for "C#" ends here... // Test case for "C++" @@ -36,6 +46,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('cpp')), ); }); + + it('should return C++ data based on prism tag "cpp"', () => { + expect(getLanguageData({ prismTag: 'cpp' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'cpp'), + ); + }); // Test case for "C++" ends here... // Test case for "Dart" @@ -48,6 +64,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('dart')), ); }); + + it('should return Dart data based on prism tag "dart"', () => { + expect(getLanguageData({ prismTag: 'dart' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'dart'), + ); + }); // Test case for "Dart" ends here... // Test case for "F#" @@ -60,6 +82,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('fs')), ); }); + + it('should return F# data based on prism tag "fsharp"', () => { + expect(getLanguageData({ prismTag: 'fsharp' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'fsharp'), + ); + }); // Test case for "F#" ends here... // Test case for "GO" @@ -72,6 +100,10 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('go')), ); }); + + it('should return GO data based on prism tag "go"', () => { + expect(getLanguageData({ prismTag: 'go' })).toEqual(LanguageData.filter((language) => language.prismTag === 'go')); + }); // Test case for "GO" ends here... // Test case for "Haskell" @@ -86,6 +118,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('hs')), ); }); + + it('should return Haskell data based on prism tag "haskell"', () => { + expect(getLanguageData({ prismTag: 'haskell' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'haskell'), + ); + }); // Test case for "Haskell" ends here... // Test case for "Java" @@ -98,6 +136,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('java')), ); }); + + it('should return Java data based on prism tag "java"', () => { + expect(getLanguageData({ prismTag: 'java' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'java'), + ); + }); // Test case for "Java" ends here... // Test case for "JavaScript" @@ -112,6 +156,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('js')), ); }); + + it('should return JavaScript data based on prism tag "javascript"', () => { + expect(getLanguageData({ prismTag: 'javascript' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'javascript'), + ); + }); // Test case for "JavaScript" ends here... // Test case for "Julia" @@ -124,6 +174,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('jl')), ); }); + + it('should return Julia data based on prism tag "julia"', () => { + expect(getLanguageData({ prismTag: 'julia' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'julia'), + ); + }); // Test case for "Julia" ends here... // Test case for "Kotlin" @@ -136,6 +192,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('kt')), ); }); + + it('should return Kotlin data based on prism tag "kotlin"', () => { + expect(getLanguageData({ prismTag: 'kotlin' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'kotlin'), + ); + }); // Test case for "Kotlin" ends here... // Test case for "Perl" @@ -148,6 +210,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('pl')), ); }); + + it('should return Perl data based on prism tag "perl"', () => { + expect(getLanguageData({ prismTag: 'perl' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'perl'), + ); + }); // Test case for "Perl" ends here... // Test case for "PHP" @@ -160,6 +228,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('php')), ); }); + + it('should return PHP data based on prism tag "php"', () => { + expect(getLanguageData({ prismTag: 'php' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'php'), + ); + }); // Test case for "PHP" ends here... // Test case for "Python" @@ -172,6 +246,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('py')), ); }); + + it('should return Python data based on prism tag "python"', () => { + expect(getLanguageData({ prismTag: 'python' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'python'), + ); + }); // Test case for "Python" ends here... // Test case for "R" @@ -184,6 +264,10 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('r')), ); }); + + it('should return R data based on prism tag "r"', () => { + expect(getLanguageData({ prismTag: 'r' })).toEqual(LanguageData.filter((language) => language.prismTag === 'r')); + }); // Test case for "R" ends here... // Test case for "Ruby" @@ -196,6 +280,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('rb')), ); }); + + it('should return Ruby data based on prism tag "ruby"', () => { + expect(getLanguageData({ prismTag: 'ruby' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'ruby'), + ); + }); // Test case for "Ruby" ends here... // Test case for "Rust" @@ -208,6 +298,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('rs')), ); }); + + it('should return Rust data based on prism tag "rust"', () => { + expect(getLanguageData({ prismTag: 'rust' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'rust'), + ); + }); // Test case for "Rust" ends here... // Test case for "Scala" @@ -220,6 +316,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('scala')), ); }); + + it('should return Scala data based on prism tag "scala"', () => { + expect(getLanguageData({ prismTag: 'scala' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'scala'), + ); + }); // Test case for "Scala" ends here... // Test case for "Swift" @@ -232,6 +334,12 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('swift')), ); }); + + it('should return Swift data based on prism tag "swift"', () => { + expect(getLanguageData({ prismTag: 'swift' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'swift'), + ); + }); // Test case for "Swift" ends here... // Test case for "TypeScript" @@ -246,5 +354,11 @@ describe('Get Language Data', () => { LanguageData.filter((language) => language.fileExtension.includes('ts')), ); }); + + it('should return TypeScript data based on prism tag "typescript"', () => { + expect(getLanguageData({ prismTag: 'typescript' })).toEqual( + LanguageData.filter((language) => language.prismTag === 'typescript'), + ); + }); // Test case for "TypeScript" ends here... }); diff --git a/src/getLanguageData/index.ts b/src/getLanguageData/index.ts index 0c56d2b..4dd2d17 100644 --- a/src/getLanguageData/index.ts +++ b/src/getLanguageData/index.ts @@ -1,7 +1,11 @@ import LanguageData from '../data'; import type { LanguageDataType, GetLanguageDataInputType } from '../type'; -export default function getLanguageData({ name, fileExtension }: GetLanguageDataInputType): LanguageDataType[] { +export default function getLanguageData({ + name, + fileExtension, + prismTag, +}: GetLanguageDataInputType): LanguageDataType[] { const language = LanguageData.filter((languageData) => { if (name) { return languageData.name.toLowerCase() === name.toLowerCase(); @@ -10,6 +14,8 @@ export default function getLanguageData({ name, fileExtension }: GetLanguageData fileExtension = fileExtension.slice(1); } return languageData.fileExtension.includes(fileExtension); + } else if (prismTag) { + return languageData.prismTag === prismTag; } }); diff --git a/src/type.ts b/src/type.ts index b02e8fb..2edc613 100644 --- a/src/type.ts +++ b/src/type.ts @@ -9,6 +9,7 @@ export type LanguageDataType = { export type GetLanguageDataInputType = { name?: string; fileExtension?: string; + prismTag?: string; }; export type RenameFileInputType = {