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

gettext-extractor-vue

Package Overview
Dependencies
Maintainers
6
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gettext-extractor-vue - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [5.1.0](https://gitlab.com/gitlab-org/frontend/gettext-extractor-vue/compare/v5.0.0...v5.1.0) (2023-03-22)
### Features
* Add supports for an optional guard ([6cbeddc](https://gitlab.com/gitlab-org/frontend/gettext-extractor-vue/commit/6cbeddc988baed25ec38d1ee051666b97aa20fd5))
# [5.0.0](https://gitlab.com/gitlab-org/frontend/gettext-extractor-vue/compare/v4.0.2...v5.0.0) (2021-02-14)

@@ -2,0 +9,0 @@

8

lib/extractJSSnippets.js

@@ -1,7 +0,5 @@

const fs = require('fs');
const extractJSSnippets = (filename) => {
const extractJSSnippets = (code, filename) => {
const snippets = [];
snippets.push({
code: fs.readFileSync(filename, 'utf8'),
code,
filename,

@@ -11,5 +9,5 @@ line: 1,

return Promise.resolve(snippets);
return snippets;
};
module.exports = extractJSSnippets;
const extractVue2Snippets = require('./extractVue2Snippets');
const extractVue3Snippets = require('./extractVue3Snippets');
const extractJSSnippets = require('./extractJSSnippets');
const fs = require('fs').promises;

@@ -8,2 +9,3 @@ const extractSnippetsFactory = ({

vue3TemplateCompiler = null,
guard = null,
} = {}) => {

@@ -22,16 +24,15 @@ if (vue2TemplateCompiler && vue3TemplateCompiler) {

if (vue2TemplateCompiler) {
return (file) => {
if (file.endsWith('vue')) {
return extractVue2Snippets(file, vue2TemplateCompiler);
}
return extractJSSnippets(file);
};
}
const USE_VUE_2 = Boolean(vue2TemplateCompiler);
return (file) => {
return async (file) => {
const content = await fs.readFile(file, 'utf-8');
if (guard && content.indexOf(guard) < 0) {
return [];
}
if (file.endsWith('vue')) {
return extractVue3Snippets(file, vue3TemplateCompiler);
return USE_VUE_2
? extractVue2Snippets(content, file, vue2TemplateCompiler)
: extractVue3Snippets(content, file, vue3TemplateCompiler);
}
return extractJSSnippets(file);
return extractJSSnippets(content, file);
};

@@ -38,0 +39,0 @@ };

@@ -1,53 +0,43 @@

const fs = require('fs');
const extractVue2Snippets = (file, filename, compiler) => {
const source = compiler.parseComponent(file, { pad: 'line' });
const extractVue2Snippets = (filename, compiler) => {
return new Promise((resolve, reject) => {
fs.readFile(filename, 'utf8', (err, file) => {
if (err) {
return reject(err);
}
const snippets = [];
const source = compiler.parseComponent(file, { pad: 'line' });
if (source.template && source.template.content) {
const count = (file.substr(0, source.template.start + 1).match(/[\r\n]/g) || []).length;
const snippets = [];
const compiled = compiler.compile(source.template.content);
if (source.template && source.template.content) {
const count = (file.substr(0, source.template.start + 1).match(/[\r\n]/g) || []).length;
snippets.push({
code: compiled.render,
filename,
line: count + 1,
});
const compiled = compiler.compile(source.template.content);
compiled.staticRenderFns.forEach((fn) => {
snippets.push({
code: fn,
filename,
line: count + 1,
});
});
}
snippets.push({
code: compiled.render,
filename,
line: count + 1,
});
if (source.script && source.script.content) {
const scriptSnippet = {
code: source.script.content,
filename,
line: 1,
};
compiled.staticRenderFns.forEach((fn) => {
snippets.push({
code: fn,
filename,
line: count + 1,
});
});
}
if (snippets.length && source.script.start < source.template.start) {
snippets.unshift(scriptSnippet);
} else {
snippets.push(scriptSnippet);
}
}
if (source.script && source.script.content) {
const scriptSnippet = {
code: source.script.content,
filename,
line: 1,
};
if (snippets.length && source.script.start < source.template.start) {
snippets.unshift(scriptSnippet);
} else {
snippets.push(scriptSnippet);
}
}
return resolve(snippets);
});
});
return snippets;
};
module.exports = extractVue2Snippets;

@@ -1,50 +0,37 @@

const fs = require('fs');
const extractVue3Snippets = (file, filename, compiler) => {
const { descriptor } = compiler.parse(file, { pad: 'line', filename });
const extractVue3Snippets = (filename, compiler) => {
return new Promise((resolve, reject) => {
fs.readFile(filename, 'utf8', (err, file) => {
if (err) {
return reject(err);
}
const snippets = [];
const { descriptor } = compiler.parse(file, { pad: 'line', filename });
if (descriptor.template && descriptor.template.content) {
const compiled = compiler.compileTemplate({
source: descriptor.template.content,
filename,
id: filename,
});
const snippets = [];
snippets.push({
code: compiled.code.replace(/_ctx\./g, ''),
filename,
line: descriptor.template.loc.start.line + 1,
});
}
if (descriptor.template && descriptor.template.content) {
const compiled = compiler.compileTemplate({
source: descriptor.template.content,
filename,
id: filename,
});
if (descriptor.script && descriptor.script.content) {
const scriptSnippet = {
code: descriptor.script.content,
filename,
line: descriptor.script.loc.start.line,
};
snippets.push({
code: compiled.code.replace(/_ctx\./g, ''),
filename,
line: descriptor.template.loc.start.line + 1,
});
}
if (snippets.length && descriptor.script.loc.start.line < descriptor.template.loc.start.line) {
snippets.unshift(scriptSnippet);
} else {
snippets.push(scriptSnippet);
}
}
if (descriptor.script && descriptor.script.content) {
const scriptSnippet = {
code: descriptor.script.content,
filename,
line: descriptor.script.loc.start.line,
};
if (
snippets.length &&
descriptor.script.loc.start.line < descriptor.template.loc.start.line
) {
snippets.unshift(scriptSnippet);
} else {
snippets.push(scriptSnippet);
}
}
return resolve(snippets);
});
});
return snippets;
};
module.exports = extractVue3Snippets;
{
"name": "gettext-extractor-vue",
"version": "5.0.0",
"version": "5.1.0",
"description": "Extend gettext-extractor with the possibility to parse Vue single file components",

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

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