You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@biesbjerg/ng2-translate-extract

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@biesbjerg/ng2-translate-extract - npm Package Compare versions

Comparing version

to
0.2.3

bin/template.json

4

dist/example.js
"use strict";
const extractor_1 = require('./extractor');
const json_serializer_1 = require('./serializers/json.serializer');
const extractor_1 = require("./extractor");
const json_serializer_1 = require("./serializers/json.serializer");
const serializer = new json_serializer_1.JsonSerializer();

@@ -5,0 +5,0 @@ // Or const serializer = new PotSerializer();

"use strict";
const pipe_parser_1 = require('./parsers/pipe.parser');
const pipe_parser_1 = require("./parsers/pipe.parser");
const directive_parser_1 = require("./parsers/directive.parser");
const service_parser_1 = require('./parsers/service.parser');
const lodash = require('lodash');
const glob = require('glob');
const fs = require('fs');
const service_parser_1 = require("./parsers/service.parser");
const lodash = require("lodash");
const glob = require("glob");
const fs = require("fs");
class Extractor {

@@ -9,0 +9,0 @@ constructor(serializer) {

@@ -8,3 +8,3 @@ "use strict";

_isAngularComponent(filePath) {
return new RegExp('\.(ts|js)$', 'i').test(filePath);
return new RegExp(/\.(ts|js)$/, 'i').test(filePath);
}

@@ -15,5 +15,5 @@ /**

_extractInlineTemplate(contents) {
const match = new RegExp('template\\s?:\\s?(("|\'|`)(.|[\\r\\n])+?[^\\\\]\\2)').exec(contents);
const match = new RegExp(/template\s?:\s?("|\'|`)((.|[\r\n])+?[^\\])\1/).exec(contents);
if (match !== null) {
return match[1];
return match[2];
}

@@ -20,0 +20,0 @@ return '';

"use strict";
const abstract_template_parser_1 = require('./abstract-template.parser');
const $ = require('cheerio');
const abstract_template_parser_1 = require("./abstract-template.parser");
const $ = require("cheerio");
class DirectiveParser extends abstract_template_parser_1.AbstractTemplateParser {

@@ -15,12 +15,18 @@ process(filePath, contents) {

$(template)
.find('[translate]')
.find('[translate],[ng2-translate]')
.addBack()
.each((i, element) => {
const $element = $(element);
const attr = $element.attr('translate');
const text = $element.text().trim();
if (attr) {
results.push(attr);
}
else if (text) {
results.push(text);
else {
$element
.contents()
.toArray()
.filter(textNode => textNode.type === 'text')
.map(textNode => textNode.nodeValue.trim())
.filter(text => text.length > 0)
.forEach(text => results.push(text));
}

@@ -27,0 +33,0 @@ });

"use strict";
const abstract_template_parser_1 = require('./abstract-template.parser');
const abstract_template_parser_1 = require("./abstract-template.parser");
class PipeParser extends abstract_template_parser_1.AbstractTemplateParser {

@@ -12,3 +12,3 @@ process(filePath, contents) {

let results = [];
const regExp = new RegExp('([\'"`])([^\\1\\r\\n]*)\\1\\s+\\|\\s*translate(:.*?)?', 'g');
const regExp = new RegExp(/([\'"`])([^\1\r\n]*)\1\s+\|\s*translate(:.*?)?/, 'g');
let matches;

@@ -15,0 +15,0 @@ while (matches = regExp.exec(template)) {

@@ -5,5 +5,13 @@ import { ParserInterface } from './parser.interface';

/**
* Extract name of TranslateService variable for use in patterns
* Checks if string contains an array
*/
protected _stringContainsArray(input: string): boolean;
/**
* Converts string to array
*/
protected _stringToArray(input: string): string[];
/**
* Extracts name of TranslateService variable for use in patterns
*/
protected _extractTranslateServiceVar(contents: string): string;
}

@@ -9,7 +9,12 @@ "use strict";

}
const methodPattern = '(?:get|instant)\\s*\\\(\\s*([\'"`])([^\\1\\r\\n]+)\\1';
const regExp = new RegExp(`${translateServiceVar}\.${methodPattern}`, 'g');
const methodRegExp = new RegExp(/(?:get|instant)\s*\(\s*(\[?([\'"`])([^\1\r\n]+)\2\]?)/);
const regExp = new RegExp(`${translateServiceVar}\.${methodRegExp.source}`, 'g');
let matches;
while (matches = regExp.exec(contents)) {
results.push(matches[2]);
if (this._stringContainsArray(matches[1])) {
results.push(...this._stringToArray(matches[1]));
}
else {
results.push(matches[3]);
}
}

@@ -19,4 +24,19 @@ return results;

/**
* Extract name of TranslateService variable for use in patterns
* Checks if string contains an array
*/
_stringContainsArray(input) {
return input.startsWith('[') && input.endsWith(']');
}
/**
* Converts string to array
*/
_stringToArray(input) {
if (this._stringContainsArray(input)) {
return eval(input);
}
return [];
}
/**
* Extracts name of TranslateService variable for use in patterns
*/
_extractTranslateServiceVar(contents) {

@@ -23,0 +43,0 @@ const matches = contents.match(/([a-z0-9_]+)\s*:\s*TranslateService/i);

{
"name": "@biesbjerg/ng2-translate-extract",
"version": "0.2.2",
"version": "0.2.3",
"description": "Extract strings from projects using ng2-translate",

@@ -18,3 +18,4 @@ "main": "dist/index.js",

"clean": "rm -rf ./dist",
"lint": "tslint --force './src/**/*.ts'"
"lint": "tslint --force './src/**/*.ts'",
"test": "mocha -r ts-node/register tests/**/*.spec.ts"
},

@@ -45,5 +46,10 @@ "repository": {

"devDependencies": {
"@types/chai": "^3.4.34",
"@types/cheerio": "^0.17.31",
"@types/glob": "^5.0.30",
"@types/lodash": "^4.14.41",
"@types/mocha": "^2.2.33",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"ts-node": "^1.7.0",
"tslint": "^4.0.2",

@@ -50,0 +56,0 @@ "tslint-eslint-rules": "^3.1.0",

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

Sorry, the diff of this file is not supported yet