Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ewb/translate

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ewb/translate - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

lib/ApiBranch.d.ts

10

lib/Branch.d.ts
import Empty from './Empty';
import { WordTranslations } from './Tree';
import ApiBranch from './ApiBranch';
export interface BranchObject {

@@ -9,3 +10,3 @@ [key: string]: Branch;

}
export default class Branch {
export default class Branch extends ApiBranch {
level: number;

@@ -15,7 +16,6 @@ sentence: boolean;

isWord: boolean;
word: string;
translations: Translations;
constructor(level: number, word: string, sentence?: boolean, translations?: Translations);
add(newWord: string, translations?: Translations): boolean;
constructor(level: number, word: string, sentence?: boolean, translations?: Translations, apiID?: string);
add(newWord: string, translations?: Translations, apiID?: string): boolean;
find(word: string): Branch | Empty;
addTranslations(translations: Translations): void;
addTranslation(locale: string, translation: string): void;

@@ -22,0 +22,0 @@ translate(locale: string): string | this;

@@ -6,4 +6,6 @@ "use strict";

const helpers_1 = require("./utils/helpers");
class Branch {
constructor(level, word, sentence = false, translations = {}) {
const ApiBranch_1 = require("./ApiBranch");
class Branch extends ApiBranch_1.default {
constructor(level, word, sentence = false, translations = {}, apiID = '') {
super(helpers_1.getWord(level, word, sentence));
this.level = level;

@@ -13,7 +15,5 @@ this.sentence = sentence;

this.isWord = false;
this.translations = {};
this.word = helpers_1.getWord(level, word, sentence);
const char = this.getNextCharacter(word);
if (char) {
this.words[char] = new Branch(this.level + 1, word, sentence, translations);
this.words[char] = new Branch(this.level + 1, word, sentence, translations, apiID);
}

@@ -23,5 +23,6 @@ else {

this.isWord = true;
this.apiID = apiID;
}
}
add(newWord, translations) {
add(newWord, translations, apiID) {
if (this.match(newWord)) {

@@ -38,6 +39,6 @@ if (!this.isWord) {

if (this.words[char]) {
this.words[char].add(newWord, translations);
this.words[char].add(newWord, translations, apiID);
}
else {
this.words[char] = new Branch(this.level + 1, newWord, this.sentence, translations);
this.words[char] = new Branch(this.level + 1, newWord, this.sentence, translations, apiID);
}

@@ -59,2 +60,9 @@ return true;

}
addTranslations(translations) {
for (const lang in translations) {
if (translations.hasOwnProperty(lang)) {
this.addTranslation(lang, translations[lang]);
}
}
}
addTranslation(locale, translation) {

@@ -61,0 +69,0 @@ this.translations[locale] = translation;

import Branch, { Translations } from './Branch';
import Tree from './Tree';
export default class Empty {
import ApiBranch from './ApiBranch';
export default class Empty extends ApiBranch {
branch: Branch | Tree;
addWord: string;
isTreeText: boolean;
word: null;
constructor(branch: Branch | Tree, addWord: string, isTreeText?: boolean);
apiID: string;
constructor(branch: Branch | Tree, word: string, isTreeText?: boolean);
translate(_: string): string;

@@ -10,0 +10,0 @@ add(translations?: Translations): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Empty {
constructor(branch, addWord, isTreeText = false) {
const Branch_1 = require("./Branch");
const ApiBranch_1 = require("./ApiBranch");
class Empty extends ApiBranch_1.default {
constructor(branch, word, isTreeText = false) {
super(word);
this.branch = branch;
this.addWord = addWord;
this.isTreeText = isTreeText;
this.word = null;
this.apiID = '';
}
translate(_) {
return `N/W (${this.addWord})`;
return `N/W (${this.word})`;
}
add(translations) {
if ('isWord' in this.branch) {
this.branch.add(this.addWord, translations);
if (this.branch instanceof Branch_1.default) {
this.branch.add(this.word, translations, this.apiID);
}
else {
if (this.isTreeText) {
this.branch.addText(this.addWord, translations);
this.branch.addText(this.word, translations, this.apiID);
}
else {
this.branch.addWord(this.addWord, translations);
this.branch.addWord(this.word, translations, this.apiID);
}

@@ -24,0 +26,0 @@ }

import Tree, { WordTranslations, TreeOptions } from './Tree';
import Empty from './Empty';
import Branch, { Translations, BranchObject } from './Branch';
import { ISO_639_1 } from './utils/iso_639_1';
declare type NoMatchFn = (translate: Translate, empty: Empty) => void;

@@ -41,2 +42,2 @@ declare type NoTranslationFn = (translate: Translate, empty: Branch) => void;

}
export { Tree, Empty, Branch, Translate, TranslateOptions, WordTranslations, TreeOptions, Translations, BranchObject, Variables, TextOptions };
export { Tree, Empty, Branch, Translate, TranslateOptions, WordTranslations, TreeOptions, Translations, BranchObject, Variables, TextOptions, ISO_639_1 };

@@ -14,2 +14,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Translate = exports.Branch = exports.Empty = exports.Tree = void 0;
const Tree_1 = require("./Tree");

@@ -16,0 +17,0 @@ exports.Tree = Tree_1.default;

@@ -16,4 +16,4 @@ import Branch, { BranchObject, Translations } from './Branch';

constructor({ words, texts }: TreeOptions);
addWord(word: string, translations?: Translations): void;
addText(text: string, translations?: Translations): void;
addWord(word: string, translations?: Translations, apiID?: string): void;
addText(text: string, translations?: Translations, apiID?: string): void;
word(word: string): Branch | Empty;

@@ -20,0 +20,0 @@ text(text: string): Branch | Empty;

@@ -13,18 +13,18 @@ "use strict";

}
addWord(word, translations) {
addWord(word, translations, apiID) {
const char = helpers_1.getFirst(word);
if (this.words[char]) {
this.words[char].add(word, translations);
this.words[char].add(word, translations, apiID);
}
else {
this.words[char] = new Branch_1.default(0, word, false, translations);
this.words[char] = new Branch_1.default(0, word, false, translations, apiID);
}
}
addText(text, translations) {
addText(text, translations, apiID) {
const word = helpers_1.getFirst(text, true);
if (this.texts[word]) {
this.texts[word].add(text, translations);
this.texts[word].add(text, translations, apiID);
}
else {
this.texts[word] = new Branch_1.default(0, text, true, translations);
this.texts[word] = new Branch_1.default(0, text, true, translations, apiID);
}

@@ -31,0 +31,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayToObject = exports.getFirst = exports.suggestions = exports.getWord = exports.VARIABLE_REGEXP = void 0;
exports.VARIABLE_REGEXP = /{{(.*?)}}/g;

@@ -4,0 +5,0 @@ function getWord(level, word, sentence = false) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.add = void 0;
exports.add = (a, b) => a + b;
//# sourceMappingURL=math.js.map
{
"name": "@ewb/translate",
"version": "1.2.3",
"version": "1.3.0",
"description": "Translate as you create your app. Saves the words and text in a tree structure for fast and easy lookup.",

@@ -13,2 +13,3 @@ "main": "./lib/index.js",

"test:watch": "mocha --watch --watch-extensions ts -r ts-node/register test/**/*.spec.ts",
"test:active": "mocha --watch --watch-extensions ts -r ts-node/register test/**/*.spec.ts --grep active:",
"test": "mocha -r ts-node/register test/**/*.spec.ts",

@@ -49,6 +50,9 @@ "coverage": "nyc mocha -r ts-node/register test/**/*.spec.ts",

"@types/mocha": "^5.2.7",
"@types/node-fetch": "^2.5.7",
"chai": "^4.2.0",
"coveralls": "^3.0.9",
"fetch-mock": "^9.10.2",
"husky": "^4.0.10",
"mocha": "^7.0.0",
"node-fetch": "^2.6.0",
"nyc": "^15.0.0",

@@ -55,0 +59,0 @@ "prettier": "^1.19.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc