UNPKG

@deeplx/core

Version:

An unofficial but powerful and easy-to-use yet free DeepL API client for Node.js using [DeepL](https://www.deepl.com) by porting [OwO-Network/DeepLX](https://github.com/OwO-Network/DeepLX).

33 lines 1.24 kB
import { SUPPORTED_LANGUAGES, } from "./constants.js"; export const getICount = (translateText) => { return (translateText.match(/i/g) || []).length; }; export const getRandomNumber = () => { const base = Math.floor(Math.random() * 99_999) + 8_300_000; return base * 1000; }; export const getTimeStamp = (iCount) => { const ts = Date.now(); if (iCount !== 0) { const adjustedCount = iCount + 1; return ts - (ts % adjustedCount) + adjustedCount; } return ts; }; export const formatPostString = (postData) => { const postStr = JSON.stringify(postData); const shouldAddSpace = (postData.id + 5) % 29 === 0 || (postData.id + 3) % 13 === 0; return postStr.replaceAll('"method":"', shouldAddSpace ? `"method" : "` : `"method": "`); }; let abbreviateLanguageDictionary; function getAbbreviateLanguages() { return (abbreviateLanguageDictionary ??= SUPPORTED_LANGUAGES.reduce((acc, lang) => { acc[lang.code.toLowerCase()] = lang.code; acc[lang.language.toLowerCase()] = lang.code; return acc; }, {})); } export function abbreviateLanguage(language) { return getAbbreviateLanguages()[language.split('-')[0].toLowerCase()]; } //# sourceMappingURL=utils.js.map