├── .all-contributorsrc
├── .github
└── FUNDING.yml
├── .gitignore
├── .prettierignore
├── .prettierrc.js
├── .vscode
├── extensions.json
├── launch.json
├── settings.json
└── tasks.json
├── .vscodeignore
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── jest.config.js
├── md2urdu-1.1.1.vsix
├── package-lock.json
├── package.json
├── src
├── lib
│ ├── extension.ts
│ └── internal
│ │ ├── checkFileType.ts
│ │ ├── getFileContent.ts
│ │ ├── translate.ts
│ │ └── writeFileContent.ts
└── typings
│ ├── google-translate-api.d.ts
│ └── vscode.d.ts
├── test
└── unit
│ └── lib
│ └── internal
│ ├── checkFileType.test.ts
│ ├── example.md
│ ├── getWriteFileContent.test.ts
│ ├── import.ts
│ ├── translate.test.ts
│ └── vscode.ts
├── tsconfig.json
└── tslint.json
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "files": [
3 | "README.md"
4 | ],
5 | "imageSize": 100,
6 | "commit": false,
7 | "contributors": [
8 | {
9 | "login": "viveksharmaui",
10 | "name": "Vivek Anand Sharma",
11 | "avatar_url": "https://avatars1.githubusercontent.com/u/28563357?v=4",
12 | "profile": "https://viveksharmaui.js.org",
13 | "contributions": [
14 | "infra",
15 | "test",
16 | "code",
17 | "doc",
18 | "bug"
19 | ]
20 | },
21 | {
22 | "login": "MirFahad58",
23 | "name": "Mir Fahad Talpur",
24 | "avatar_url": "https://avatars1.githubusercontent.com/u/31244700?v=4",
25 | "profile": "https://github.com/MirFahad58",
26 | "contributions": [
27 | "doc"
28 | ]
29 | },
30 | {
31 | "login": "aliasgharkarani",
32 | "name": "Ali Asghar Karani",
33 | "avatar_url": "https://avatars0.githubusercontent.com/u/33603201?v=4",
34 | "profile": "https://aliasgharkarani.github.io/alikarani.com/",
35 | "contributions": [
36 | "code"
37 | ]
38 | },
39 | {
40 | "login": "jmrchelani",
41 | "name": "Milton",
42 | "avatar_url": "https://avatars0.githubusercontent.com/u/55441239?v=4",
43 | "profile": "http://jmrchelani.github.io",
44 | "contributions": [
45 | "code"
46 | ]
47 | }
48 | ],
49 | "contributorsPerLine": 7,
50 | "projectName": "md2urdu",
51 | "projectOwner": "devcreatives",
52 | "repoType": "github",
53 | "repoHost": "https://github.com",
54 | "skipCi": true
55 | }
56 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom: https://liberapay.com/DevCreatives/donate
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .vscode-test/
3 | *.vsix
4 | out
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .vscode-test/
3 | *.vsix
4 | .vscode
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | // prettier.config.js or .prettierrc.js
2 | module.exports = {
3 | trailingComma: 'es5',
4 | tabWidth: 4,
5 | semi: true,
6 | singleQuote: true,
7 | }
8 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // See http://go.microsoft.com/fwlink/?LinkId=827846
3 | // for the documentation about the extensions.json format
4 | "recommendations": [
5 | "ms-vscode.vscode-typescript-tslint-plugin"
6 | ]
7 | }
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | // A launch configuration that compiles the extension and then opens it inside a new window
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | {
6 | "version": "0.2.0",
7 | "configurations": [
8 | {
9 | "name": "Run Extension",
10 | "type": "extensionHost",
11 | "request": "launch",
12 | "runtimeExecutable": "${execPath}",
13 | "args": [
14 | "--extensionDevelopmentPath=${workspaceFolder}"
15 | ],
16 | "outFiles": [
17 | "${workspaceFolder}/out/**/*.js"
18 | ],
19 | "preLaunchTask": "npm: watch"
20 | },
21 | {
22 | "name": "Extension Tests",
23 | "type": "extensionHost",
24 | "request": "launch",
25 | "runtimeExecutable": "${execPath}",
26 | "args": [
27 | "--extensionDevelopmentPath=${workspaceFolder}",
28 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
29 | ],
30 | "outFiles": [
31 | "${workspaceFolder}/out/test/**/*.js"
32 | ],
33 | "preLaunchTask": "npm: watch"
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.exclude": {
4 | "out": false // set this to true to hide the "out" folder with the compiled JS files
5 | },
6 | "search.exclude": {
7 | "out": true // set this to false to include "out" folder in search results
8 | },
9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10 | "typescript.tsc.autoDetect": "off",
11 | "git.ignoreLimitWarning": true
12 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | // See https://go.microsoft.com/fwlink/?LinkId=733558
2 | // for the documentation about the tasks.json format
3 | {
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "npm",
8 | "script": "watch",
9 | "problemMatcher": "$tsc-watch",
10 | "isBackground": true,
11 | "presentation": {
12 | "reveal": "never"
13 | },
14 | "group": {
15 | "kind": "build",
16 | "isDefault": true
17 | }
18 | }
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/.vscodeignore:
--------------------------------------------------------------------------------
1 | **/*.ts
2 | tsconfig.json
3 | test
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to the "md2urdu" will be documented in this file.
4 |
5 | ## md2urdu [1.1.0] (Released)
6 | - Added jest test cases unit/integration added by [@viveksharmaui](https://github.com/viveksharmaui).
7 | - Added selected text conversion added by [@viveksharmaui](https://github.com/viveksharmaui).
8 |
9 | ## md2urdu [1.0.0] - 2019-09-01 (Released)
10 | ### Added
11 | - Added (Ctrl+Shift+P) command to convert md file added by [@viveksharmaui](https://github.com/viveksharmaui).
12 | - Added free [Google Translate API](https://www.npmjs.com/package/@vitalets/google-translate-api) to convert md file language add by [@viveksharmaui](https://github.com/viveksharmaui).
13 | - Added Notifications after convertion of file is completed added by [@viveksharmaui](https://github.com/viveksharmaui).
14 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at sharma_vivek62@yahoo.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contribution instructions
2 |
3 | ## Shipping a new functionality
4 |
5 | 1. You can only contribute on master branch.
6 | 2. Fork this repo.
7 | 3. Pull latest master branch.
8 | 4. Contribute something great.
9 | 5. Don't forget to write unit/integration/e2e/stress test.
10 | 6. Create pull request of your branch to master branch.
11 | 7. Wait for Travis CI test to be passed.
12 | 8. Wait for reviewer to review pull request file changes (This process can take upto few day's so relax).
13 | 9. Wait for admistrator to merge pull request with master branch.
14 | 10. After doing all above steps now wait to see your changes in master and in production (This process can takes upto few weeks or months when we RELEASED new version).
15 |
16 |
17 | **Happy Contributing**
18 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 md2urdu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # md2urdu (Visual Studio Code - Extension)
2 | [](#contributors)
3 |
4 | ## Introduction
5 |
6 | This is vscode extension specially written for those who want to convert .md file written in any language to urdu language.
7 |
8 | ## What we are achieving to do
9 |
10 | The purpose behind this extension is to convert md files to urdu. This extension is for those who want to convert any framework/library documentation or even anything written in .md.
11 |
12 | ## What is our goal
13 |
14 | Our goal is to make this extension as simple as possible , as lite weight as possible and as user friendly as posssible.
15 |
16 | ## Our motivation
17 |
18 | 
19 |
20 | 
21 |
22 | ## Found bug
23 |
24 | If you found any bug please add that bug in [issue](https://github.com/Techistan/md2urdu/issues) section. so that our team will solve bug as soon as possible.
25 |
26 | ## How you can contribute
27 |
28 | This extension is open source anyone can contribute. we are always ready for new ideas and new functionalities so pull request are always welcome or see [CONTRIBUTING.md](https://github.com/Techistan/md2urdu/blob/master/CONTRIBUTING.md) file for more information.
29 |
30 | We are thinking to go further with this, we are planing to convert any selected text to urdu from any file .ts, .js and others, so contribute in this project to prove your skills.
31 |
32 | **Happy Contributing**
33 | ## Contributors ✨
34 |
35 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
36 |
37 |
38 |
39 |
40 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | roots: ['/test'],
3 | transform: {
4 | '^.+\\.tsx?$': 'ts-jest',
5 | },
6 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
8 | moduleDirectories: ['node_modules', 'src'],
9 | }
10 |
--------------------------------------------------------------------------------
/md2urdu-1.1.1.vsix:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devcreatives/md2urdu/80a743137b38189fccd7483993ff73b1fbbef4e7/md2urdu-1.1.1.vsix
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "md2urdu",
3 | "displayName": "md2urdu",
4 | "publisher": "vivek",
5 | "description": "converts any text in .md file to urdu",
6 | "version": "1.1.1",
7 | "engines": {
8 | "vscode": "^1.52.0"
9 | },
10 | "categories": [
11 | "Other"
12 | ],
13 | "activationEvents": [
14 | "onCommand:extension.md2urdu"
15 | ],
16 | "main": "./out/lib/extension.js",
17 | "contributes": {
18 | "commands": [
19 | {
20 | "command": "extension.md2urdu",
21 | "title": "converts any text in .md file to urdu"
22 | }
23 | ]
24 | },
25 | "scripts": {
26 | "vscode:prepublish": "npm run compile",
27 | "compile": "tsc -p ./",
28 | "watch": "tsc -watch -p ./",
29 | "pretest": "npm run compile",
30 | "test": "node ./out/test/runTest.js",
31 | "test:jest": "jest",
32 | "prettier": "prettier --write src/**/*.ts"
33 | },
34 | "husky": {
35 | "hooks": {
36 | "pre-commit": "npm run prettier",
37 | "pre-push": "npm run test:jest"
38 | }
39 | },
40 | "devDependencies": {
41 | "@types/glob": "^7.1.3",
42 | "@types/jest": "^26.0.20",
43 | "@types/mocha": "^8.2.0",
44 | "@types/node": "^14.14.20",
45 | "@types/vscode": "^1.52.0",
46 | "glob": "^7.1.6",
47 | "husky": "^4.3.7",
48 | "jest": "^26.6.3",
49 | "mocha": "^8.2.1",
50 | "prettier": "^2.2.1",
51 | "ts-jest": "^26.4.4",
52 | "tslint": "^5.20.1",
53 | "typescript": "^4.1.3",
54 | "vscode-test": "^1.4.1"
55 | },
56 | "dependencies": {
57 | "@vitalets/google-translate-api": "git://github.com/vkedwardli/google-translate-api.git"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/lib/extension.ts:
--------------------------------------------------------------------------------
1 | // The module 'vscode' contains the VS Code extensibility API
2 | // Import the module and reference it with the alias vscode in your code below
3 | import * as vscode from 'vscode';
4 | const fs = require('fs');
5 | const translate = require('@vitalets/google-translate-api');
6 | const CheckFileType = require('./internal/checkFileType');
7 | const GetFileContent = require('./internal/getFileContent');
8 | const WriteFileContent = require('./internal/writeFileContent');
9 | const Translate = require('./internal/translate');
10 |
11 | // this method is called when your extension is activated
12 | // your extension is activated the very first time the command is executed
13 | export function activate(context: vscode.ExtensionContext) {
14 | // Use the console to output diagnostic information (console.log) and errors (console.error)
15 | // This line of code will only be executed once when your extension is activated
16 |
17 | // The command has been defined in the package.json file
18 | // Now provide the implementation of the command with registerCommand
19 | // The commandId parameter must match the command field in package.json
20 | let disposable = vscode.commands.registerCommand(
21 | 'extension.md2urdu',
22 | async () => {
23 | // The code you place here will be executed every time your command is executed
24 | const fileTypeResult = new CheckFileType(vscode);
25 | const { checkFileType } = fileTypeResult;
26 | const { isMDFile, filePath } = await checkFileType();
27 | if (isMDFile) {
28 | vscode.window.showInformationMessage(
29 | 'Converting MD File To Urdu'
30 | );
31 | const getFileContentResult = new GetFileContent(vscode, fs);
32 | const { getFileContent } = getFileContentResult;
33 | const { fileData, selectedTexted } = await getFileContent(
34 | filePath
35 | );
36 | if (fileData && !selectedTexted) {
37 | const translateResult = new Translate(translate, vscode);
38 | const { translation } = translateResult;
39 | const fileDataInUrdu = await translation(fileData);
40 | if (fileDataInUrdu) {
41 | const writeFileContentResult = new WriteFileContent(
42 | vscode,
43 | fs
44 | );
45 | const { writeFileContent } = writeFileContentResult;
46 | const writeData = await writeFileContent(
47 | filePath,
48 | fileDataInUrdu
49 | );
50 | if (writeData) {
51 | vscode.window.showInformationMessage(
52 | 'Successfully Converted MD File To Urdu'
53 | );
54 | } else {
55 | vscode.window.showInformationMessage(
56 | 'Unable To Write Urdu Data In MD File'
57 | );
58 | }
59 | } else {
60 | vscode.window.showInformationMessage(
61 | 'Unable To Translate MD File Data'
62 | );
63 | }
64 | } else if (fileData && selectedTexted) {
65 | const translateResult = new Translate(translate, vscode);
66 | const { translation } = translateResult;
67 | const selectedTextInUrdu = await translation(
68 | selectedTexted
69 | );
70 | if (selectedTextInUrdu) {
71 | const fileDataWithSelectedText = fileData.replace(
72 | selectedTexted,
73 | selectedTextInUrdu
74 | );
75 | const writeFileContentResult = new WriteFileContent(
76 | vscode,
77 | fs
78 | );
79 | const { writeFileContent } = writeFileContentResult;
80 | const writeData = await writeFileContent(
81 | filePath,
82 | fileDataWithSelectedText
83 | );
84 | //Used variables instead of re writing the event again and again it self.
85 | let showInformationMessage = '';
86 | if (writeData) {
87 | showInformationMessage =
88 | 'Successfully Converted MD File To Urdu';
89 | } else {
90 | showInformationMessage =
91 | 'Unable To Write Urdu Data In MD File';
92 | }
93 | vscode.window.showInformationMessage(
94 | showInformationMessage
95 | );
96 | } else {
97 | vscode.window.showInformationMessage(
98 | 'Unable To Translate MD File Data'
99 | );
100 | }
101 | } else {
102 | vscode.window.showInformationMessage(
103 | 'Unable To Get MD File Data'
104 | );
105 | }
106 | } else {
107 | vscode.window.showInformationMessage(
108 | 'Current File Is Not MD File'
109 | );
110 | }
111 | }
112 | );
113 | context.subscriptions.push(disposable);
114 | }
115 |
116 | // this method is called when your extension is deactivated
117 | export function deactivate() {
118 | vscode.window.showInformationMessage('md2urdu is deactivated');
119 | }
120 |
--------------------------------------------------------------------------------
/src/lib/internal/checkFileType.ts:
--------------------------------------------------------------------------------
1 | // This class is responsible for getting current editor file type
2 |
3 | // CheckFileType Class
4 | // Getting information of current open file if that file is markdown get content of file
5 | module.exports = class CheckFileType {
6 | vscode: any;
7 | constructor(vscode: any) {
8 | this.vscode = vscode;
9 | }
10 | // this method is called for checking current open file
11 | checkFileType = async () => {
12 | const vscode = this.vscode;
13 | let response;
14 | let filePath;
15 | const { _documentData } = vscode.window.activeTextEditor;
16 | const { _languageId, _document } = _documentData;
17 | const { fileName } = _document;
18 | if (_languageId === 'markdown') {
19 | response = true;
20 | filePath = fileName;
21 | }
22 | return { isMDFile: response, filePath };
23 | };
24 | };
25 |
--------------------------------------------------------------------------------
/src/lib/internal/getFileContent.ts:
--------------------------------------------------------------------------------
1 | // This class is responsible for getting file content
2 |
3 | module.exports = class GetFileContent {
4 | vscode: any;
5 | fs: any;
6 | constructor(vscode: any, fs: any) {
7 | this.vscode = vscode;
8 | this.fs = fs;
9 | }
10 | // this method is called for getting content of current file
11 | getFileContent = async (fileName: string) => {
12 | const fs = this.fs;
13 | const vscode = this.vscode;
14 | return new Promise(function(resolve: any, reject: any) {
15 | fs.readFile(fileName, async (err: any, data: any) => {
16 | if (!err) {
17 | const selectedTexted = vscode.window.activeTextEditor.document.getText(
18 | vscode.window.activeTextEditor.selection
19 | );
20 | const fileData = await data.toString();
21 | resolve({ fileData, selectedTexted });
22 | } else {
23 | vscode.window.showInformationMessage(
24 | '.md Not Converted to urdu'
25 | );
26 | reject(undefined);
27 | }
28 | });
29 | });
30 | };
31 | };
32 |
--------------------------------------------------------------------------------
/src/lib/internal/translate.ts:
--------------------------------------------------------------------------------
1 | // This class is responsible for translations
2 |
3 | module.exports = class Translate {
4 | translate: any;
5 | vscode: any;
6 | constructor(translate: any, vscode: any) {
7 | this.translate = translate;
8 | this.vscode = vscode;
9 | }
10 | // this method will translate string
11 | translation = async (fileData: string) => {
12 | return await this.translate(fileData, { to: 'ur' })
13 | .then((res: any) => {
14 | if (!res)
15 | this.vscode.window.showInformationMessage(
16 | 'Unable to convert'
17 | );
18 | else {
19 | const urduText = res.text;
20 | return urduText;
21 | }
22 | })
23 | .catch((err: object) => {
24 | this.vscode.window.showInformationMessage('Unable to convert');
25 | return err;
26 | });
27 | };
28 | };
29 |
--------------------------------------------------------------------------------
/src/lib/internal/writeFileContent.ts:
--------------------------------------------------------------------------------
1 | // This class is responsible for writting file content
2 |
3 | module.exports = class WriteFileContent {
4 | vscode: any;
5 | fs: any;
6 | constructor(vscode: any, fs: any) {
7 | this.vscode = vscode;
8 | this.fs = fs;
9 | }
10 | // this method is called for writting content of current file
11 | writeFileContent = async (fileName: string, urduText: String) => {
12 | const fs = this.fs;
13 | const vscode = this.vscode;
14 | return new Promise(function(resolve: any, reject: any) {
15 | fs.writeFile(fileName, urduText, (err: any) => {
16 | if (err) reject(undefined);
17 | resolve(urduText);
18 | });
19 | });
20 | };
21 | };
22 |
--------------------------------------------------------------------------------
/src/typings/google-translate-api.d.ts:
--------------------------------------------------------------------------------
1 | declare module '@vitalets/google-translate-api';
2 |
--------------------------------------------------------------------------------
/src/typings/vscode.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'vscode';
2 |
--------------------------------------------------------------------------------
/test/unit/lib/internal/checkFileType.test.ts:
--------------------------------------------------------------------------------
1 | // This will test type of current file
2 | const checkFileTypeImport = require('./import')
3 |
4 | test('checking file type in editor', async () => {
5 | const { CheckFileType, vscode } = checkFileTypeImport
6 | const { currentWorkSpace } = vscode
7 | const fileTypeResult = new CheckFileType(currentWorkSpace)
8 | const { checkFileType } = fileTypeResult
9 | const { isMDFile } = await checkFileType()
10 | expect(isMDFile).toBe(true)
11 | })
12 |
--------------------------------------------------------------------------------
/test/unit/lib/internal/example.md:
--------------------------------------------------------------------------------
1 | آپ کیسے ہو
--------------------------------------------------------------------------------
/test/unit/lib/internal/getWriteFileContent.test.ts:
--------------------------------------------------------------------------------
1 | // This test will get file content and write file content
2 | const getWriteFileContentImport = require('./import')
3 |
4 | test('getting file content', async () => {
5 | const { GetFileContent, vscode, fs, path } = getWriteFileContentImport
6 | const { windowMessage } = vscode
7 | const { join } = path
8 | const getFileContentResult = new GetFileContent(windowMessage, fs)
9 | const { getFileContent } = getFileContentResult
10 | const exampleMdPath = join(__dirname, 'example.md')
11 | const { fileData } = await getFileContent(exampleMdPath)
12 | expect(typeof fileData).toBe('string')
13 | })
14 |
15 | test('writing in file content', async () => {
16 | const { WriteFileContent, vscode, fs, path } = getWriteFileContentImport
17 | const { windowMessage } = vscode
18 | const { join } = path
19 | const writeFileContentResult = new WriteFileContent(windowMessage, fs)
20 | const { writeFileContent } = writeFileContentResult
21 | const exampleMdPath = join(__dirname, 'example.md')
22 | const response = await writeFileContent(exampleMdPath, 'آپ کیسے ہو')
23 | expect(typeof response).toBe('string')
24 | })
25 |
--------------------------------------------------------------------------------
/test/unit/lib/internal/import.ts:
--------------------------------------------------------------------------------
1 | // All imports for test cases will be here
2 |
3 | exports.fs = require('fs')
4 | exports.path = require('path')
5 | exports.GetFileContent = require('../../../../src/lib/internal/getFileContent')
6 | exports.WriteFileContent = require('../../../../src/lib/internal/writeFileContent')
7 | exports.vscode = require('./vscode')
8 | exports.CheckFileType = require('../../../../src/lib/internal/checkFileType')
9 | exports.translate = require('@vitalets/google-translate-api')
10 | exports.Translate = require('../../../../src/lib/internal/translate')
11 |
--------------------------------------------------------------------------------
/test/unit/lib/internal/translate.test.ts:
--------------------------------------------------------------------------------
1 | // This test will translate string
2 | const translateImport = require('./import')
3 |
4 | test('translate', async () => {
5 | const { Translate, translate: translateAPI, vscode } = translateImport
6 | const { windowMessage } = vscode
7 | const translateResult = new Translate(translateAPI, windowMessage)
8 | const { translation } = translateResult
9 | const response = await translation('hello world')
10 | expect(typeof response).toBe('string')
11 | })
12 |
--------------------------------------------------------------------------------
/test/unit/lib/internal/vscode.ts:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | windowMessage: {
3 | window: {
4 | showInformationMessage: (response: String) => {
5 | console.log(response)
6 | },
7 | },
8 | },
9 | currentWorkSpace: {
10 | workspace: { textDocuments: [{ languageId: 'markdown' }] },
11 | },
12 | }
13 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "target": "es6",
5 | "outDir": "./out",
6 | "lib": [
7 | "es6"
8 | ],
9 | "sourceMap": true,
10 | "esModuleInterop": true,
11 | "skipLibCheck": true,
12 | "rootDir":"./src",
13 | "strict": true, /* enable all strict type-checking options */
14 | /* Additional Checks */
15 | "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
16 | "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
17 | "noUnusedParameters": true /* Report errors on unused parameters. */
18 | },
19 | "include": [
20 | "src"
21 | ],
22 | "exclude": [
23 | "node_modules",
24 | "vscode-test",
25 | "test"
26 | ]
27 | }
28 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "no-string-throw": true,
4 | "no-unused-expression": true,
5 | "no-duplicate-variable": true,
6 | "curly": true,
7 | "class-name": true,
8 | "semicolon": [
9 | true,
10 | "always"
11 | ],
12 | "triple-equals": true
13 | },
14 | "defaultSeverity": "warning",
15 | "extends": [
16 | "tslint:latest",
17 | "tslint-config-prettier"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------