Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Add getLanguageData by prismTag
Browse files Browse the repository at this point in the history
  • Loading branch information
harshraj8843 committed Apr 27, 2023
1 parent 70a7ab9 commit 202a50f
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/getLanguageData/index.d.ts
Original file line number Diff line number Diff line change
@@ -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[];
5 changes: 4 additions & 1 deletion lib/getLanguageData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -16,6 +16,9 @@ function getLanguageData(_a) {
}
return languageData.fileExtension.includes(fileExtension);
}
else if (prismTag) {
return languageData.prismTag === prismTag;
}
});
if (language) {
return language;
Expand Down
1 change: 1 addition & 0 deletions lib/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type LanguageDataType = {
export type GetLanguageDataInputType = {
name?: string;
fileExtension?: string;
prismTag?: string;
};
export type RenameFileInputType = {
name?: string;
Expand Down
114 changes: 114 additions & 0 deletions src/getLanguageData/__test__/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand All @@ -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++"
Expand All @@ -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"
Expand All @@ -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#"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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...
});
8 changes: 7 additions & 1 deletion src/getLanguageData/index.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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;
}
});

Expand Down
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type LanguageDataType = {
export type GetLanguageDataInputType = {
name?: string;
fileExtension?: string;
prismTag?: string;
};

export type RenameFileInputType = {
Expand Down

0 comments on commit 202a50f

Please sign in to comment.