Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ParvinEyvazov committed Dec 9, 2023
1 parent cae4fc9 commit b7348a4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.9.0",
"version": "1.10.0",
"license": "MIT",
"main": "dist/index.js",
"description": "Translate your JSON file or object into another languages with Google Translate API",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { listIOS, getLanguages, Sources, TRANSLATE_POSTFIX, translatorsNames } from '..';
import { getLanguages, Sources, TRANSLATE_POSTFIX, translatorsNames } from '..';
import { fileTranslator, getFileFromPath } from '../core/json_file';
import {
error,
Expand Down
10 changes: 6 additions & 4 deletions src/core/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs/promises';
import * as YAML from "yaml"
import * as YAML from 'yaml';
import { matchYamlExt } from '../utils/yaml';
import { error, messages } from '../utils/console';
import { default_value, translation_value_limit } from '../utils/micro';
Expand All @@ -11,9 +11,11 @@ export async function getFile(objectPath: string) {
.readFile(objectPath, 'utf8')
.then(data => {
// This function should return a string with JSON-encoded data.
// To preserve the contract, YAML files should be parsed to object
// To preserve the contract, YAML files should be parsed to object
// and then stringified to JSON string.
json_file = matchYamlExt(objectPath) ? JSON.stringify(YAML.parse(data)) : data;
json_file = matchYamlExt(objectPath)
? JSON.stringify(YAML.parse(data))
: data;
})
.catch(_ => {
json_file = undefined;
Expand All @@ -36,7 +38,7 @@ export function getRootFolder(path: string) {
}

export async function saveFilePublic(path: string, data: any) {
// When path extension is for YAML file, then stringify with YAML encoder.
// When path extension is for YAML file, then stringify with YAML encoder.
// Otherwise, default JSON encoder is used.
var json = matchYamlExt(path) ? YAML.stringify(data) : JSON.stringify(data);

Expand Down
12 changes: 7 additions & 5 deletions src/core/json_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { error, messages, success } from '../utils/console';
import { getLanguageFromCode } from '../utils/micro';
import { getFile, getRootFolder, saveFilePublic } from './core';
import { objectTranslator } from './json_object';
import { matchYamlExt } from "../utils/yaml";
import { matchYamlExt } from '../utils/yaml';

export async function fileTranslator(
objectPath: string,
Expand Down Expand Up @@ -34,10 +34,10 @@ export async function fileTranslator(
let root_folder = getRootFolder(latest_path);

// Check if source file has YAML extension and return the extension ("yml" or "yaml").
const source_file_match_yaml_ext = matchYamlExt(latest_path)
// When source file has "yml" or "yaml" extension, use the same in output file path.
const source_file_match_yaml_ext = matchYamlExt(latest_path);
// When source file has "yml" or "yaml" extension, use the same in output file path.
// Otherwise, default "json" extension used.
const file_ext = source_file_match_yaml_ext || "json";
const file_ext = source_file_match_yaml_ext || 'json';

if (Array.isArray(new_json_obj) === true && Array.isArray(to) === true) {
// multiple file saving
Expand All @@ -59,7 +59,9 @@ export async function fileTranslator(
} else {
new_json_obj = (new_json_obj as translatedObject).data;

let file_name = newFileName ? `/${newFileName}.${to}.${file_ext}` : `/${to}.${file_ext}`;
let file_name = newFileName
? `/${newFileName}.${to}.${file_ext}`
: `/${to}.${file_ext}`;

await saveFilePublic(root_folder + file_name, new_json_obj);

Expand Down
5 changes: 3 additions & 2 deletions src/utils/yaml.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
*
*
* @param objectPath path to file
* @returns File extension without leading "." ("yml" or "yaml")
*/
export const matchYamlExt = (objectPath: string) => objectPath.match(/\.(ya?ml)$/)?.[1];
export const matchYamlExt = (objectPath: string) =>
objectPath.match(/\.(ya?ml)$/)?.[1];

0 comments on commit b7348a4

Please sign in to comment.