Socket
Socket
Sign inDemoInstall

translatte

Package Overview
Dependencies
3
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.3 to 2.4.3

10

index.js

@@ -31,3 +31,3 @@ const querystring = require('querystring');

'The language «[lang]» is not supported',
'Text must not exceed 2900 characters',
'Text must not exceed 5000 bytes',
'The server returned an empty response',

@@ -46,2 +46,3 @@ 'Could not get token from google',

let bytes = languages.utf8Length(text);
opts.client = opts.client || 't';

@@ -74,6 +75,9 @@ opts.tld = opts.tld || 'com';

if (text.length > 2900) {
if (bytes > 5000) {
let chars = Math.ceil(text.length / Math.ceil(bytes / 4700)) + 100;
let texts = [];
['\\.\\s', ',\\s', '\\s'].forEach(t => {
texts = text.match(new RegExp('[^]{1,2900}(' + t + '|$)', 'ig'))
if (!texts || !texts.length) {
texts = text.match(new RegExp('[^]{1,' + chars + '}(' + t + '|$)', 'ig'));
}
});

@@ -80,0 +84,0 @@ if (!texts) return Promise.reject(errors[1]);

@@ -151,4 +151,36 @@ /**

/**
* Returns utf8 length
* @param str – string
* @returns {number}
*/
function utf8Length(str) {
var utf8 = [];
for (var i = 0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
} else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode >> 6) & 0x3f),
0x80 | (charcode & 0x3f));
}
else {
i++;
charcode = 0x10000 + (((charcode & 0x3ff) << 10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >> 18),
0x80 | ((charcode >> 12) & 0x3f),
0x80 | ((charcode >> 6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8.length;
}
module.exports = langs;
module.exports.isSupported = isSupported;
module.exports.getCode = getCode;
module.exports.getCode = getCode;
module.exports.utf8Length = utf8Length;
{
"name": "translatte",
"version": "2.3.3",
"version": "2.4.3",
"description": "A free and unlimited translate for NodeJS",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc