From b7348a4098c94461f78495dd49907d1634385a88 Mon Sep 17 00:00:00 2001 From: ParvinEyvazov Date: Sun, 10 Dec 2023 02:54:57 +0400 Subject: [PATCH] fix: lint --- package.json | 2 +- src/cli/cli.ts | 2 +- src/core/core.ts | 10 ++++++---- src/core/json_file.ts | 12 +++++++----- src/utils/yaml.ts | 5 +++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 6e23075..76945e1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli/cli.ts b/src/cli/cli.ts index cc11037..57b46a5 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -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, diff --git a/src/core/core.ts b/src/core/core.ts index bf3fc80..7ac983a 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -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'; @@ -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; @@ -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); diff --git a/src/core/json_file.ts b/src/core/json_file.ts index 7c778af..64286bc 100644 --- a/src/core/json_file.ts +++ b/src/core/json_file.ts @@ -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, @@ -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 @@ -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); diff --git a/src/utils/yaml.ts b/src/utils/yaml.ts index 604379b..0ead04d 100644 --- a/src/utils/yaml.ts +++ b/src/utils/yaml.ts @@ -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];