New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fz-propertytojson

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fz-propertytojson - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

57

lib/index.js

@@ -10,10 +10,10 @@ 'use strict';

function isComment(str) {
return str.startsWith("#");
return str.startsWith('#');
}
function stringToJson(str) {
var lines = str.split("\n");
var lines = str.split('\n');
var json = {};
lines.forEach(function (line) {
if (!isComment(line) && !(line == "")) {
var indexOfEqual = line.indexOf("=");
if (!isComment(line) && !(line == '')) {
var indexOfEqual = line.indexOf('=');
var key = line.substring(0, indexOfEqual);

@@ -28,26 +28,36 @@ var value = line.substring(indexOfEqual + 1);

}
function jsonToString(json) {
var str = "var i18n={";
function jsonToString(json, context) {
var str;
if (context) {
str = 'var ' + context.trim() + 'I18n={';
} else {
str = 'var i18n={';
}
var keys = Object.keys(json);
keys.forEach(function (key, i) {
var value = json[key];
str += "\"" + key + "\":\"" + value.replace(/.?\"/g, function (match) {
if (match[0] == "\\") {
str += '"' + key + '":"' + value.replace(/.?\"/g, function (match) {
if (match[0] == '\\') {
return match;
} else if (match.length == 2) {
return match[0] + "\\" + match[1];
return match[0] + '\\' + match[1];
} else {
return "\\" + match;
return '\\' + match;
}
}).replace(/(\r\n|\n|\r)/g, "") + "\"";
if (i != keys.length - 1) str += ",";
}).replace(/(\r\n|\n|\r)/g, '') + '"';
if (i != keys.length - 1) str += ',';
});
str += "}";
str += '}';
return str;
}
function folderIterate(propertyFolder, i18nFolder, baseProperty, jsProperty) {
function folderIterate(propertyFolder, i18nFolder, baseProperty, jsProperty, context) {
var basePropertyStr = fs.readFileSync(baseProperty).toString();
var basePropertyJson = stringToJson(basePropertyStr);
var jsPropertyStr = fs.readFileSync(jsProperty).toString();
var jsPropertyJson = stringToJson(jsPropertyStr);
try {
var jsPropertyJson = JSON.parse(jsPropertyStr);
} catch (e) {
var jsPropertyJson = stringToJson(jsPropertyStr);
}

@@ -58,5 +68,5 @@ fs.readdir(propertyFolder, function (err, files) {

if (fs.statSync(location).isDirectory()) {
console.log("dir" + file);
console.log('dir' + file);
} else {
if (location != jsProperty && file.endsWith(".properties")) {
if (location != jsProperty && location != baseProperty && file.endsWith('.properties')) {
var str = fs.readFileSync(location).toString();

@@ -68,10 +78,13 @@ var json = stringToJson(str);

}, {});
var underScoreIndex = file.indexOf("_");
var outputFileName = "en_US.js";
var underScoreIndex = file.indexOf('_');
var outputFileName = 'en_US.js';
if (underScoreIndex != -1) {
outputFileName = file.substring(underScoreIndex + 1, file.indexOf("."));
outputFileName += ".js";
outputFileName = file.substring(underScoreIndex + 1, file.indexOf('.'));
outputFileName += '.js';
}
console.log(file);
fs.writeFileSync(path.join(i18nFolder, outputFileName), jsonToString(outputJson));
if (!fs.existsSync(i18nFolder)) {
fs.mkdir(i18nFolder);
}
fs.writeFileSync(path.join(i18nFolder, outputFileName), jsonToString(outputJson, context));
}

@@ -78,0 +91,0 @@ }

{
"name": "fz-propertytojson",
"version": "1.0.2",
"version": "1.0.3",
"description": "convert propertyfile to json object",

@@ -20,8 +20,3 @@ "main": "lib/index.js",

},
"keywords": [
"properties",
"to",
"json",
"object"
],
"keywords": ["properties", "to", "json", "object"],
"author": "vimalesan.ceg@gmail.com",

@@ -34,30 +29,12 @@ "license": "MIT",

"babel": {
"presets": [
"es2015"
]
"presets": ["es2015"]
},
"jest": {
"rootDir": ".",
"testPathIgnorePatterns": [
"/node_modules/",
"/__tests__/library/"
],
"unmockedModulePathPatterns": [
"__tests__",
"node_modules",
".*"
],
"testPathDirs": [
"<rootDir>/__tests__/"
],
"testPathIgnorePatterns": ["/node_modules/", "/__tests__/library/"],
"unmockedModulePathPatterns": ["__tests__", "node_modules", ".*"],
"testPathDirs": ["<rootDir>/__tests__/"],
"collectCoverage": true,
"coverageReporters": [
"json",
"html",
"json-summary",
"text"
],
"moduleFileExtensions": [
"js"
],
"coverageReporters": ["json", "html", "json-summary", "text"],
"moduleFileExtensions": ["js"],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(jsx|js|json|node)$",

@@ -67,5 +44,3 @@ "transform": {

},
"setupFiles": [
"<rootDir>/__tests__/library/setup.jsx"
]
"setupFiles": ["<rootDir>/__tests__/library/setup.jsx"]
},

@@ -72,0 +47,0 @@ "devDependencies": {

var fs = require('fs');
var path = require('path');
function isComment(str){
return str.startsWith("#")
function isComment(str) {
return str.startsWith('#');
}
function stringToJson(str){
var lines = str.split("\n");
var json={};
lines.forEach((line)=>{
if(!isComment(line) && !(line == "")){
var indexOfEqual=line.indexOf("=");
var key = line.substring(0,indexOfEqual);
var value = line.substring(indexOfEqual+1);
if(!json[key]){
json[key] = value;
function stringToJson(str) {
var lines = str.split('\n');
var json = {};
lines.forEach(line => {
if (!isComment(line) && !(line == '')) {
var indexOfEqual = line.indexOf('=');
var key = line.substring(0, indexOfEqual);
var value = line.substring(indexOfEqual + 1);
if (!json[key]) {
json[key] = value;
}
}
})
return json
});
return json;
}
function jsonToString(json){
var str = "var i18n={";
var keys = Object.keys(json);
keys.forEach((key,i)=>{
var value=json[key];
str+="\""+key+"\":\""+value.replace(/.?\"/g,function(match){
if(match[0]=="\\"){
return match;
}
else if(match.length==2){
return match[0]+"\\"+match[1]
}
else{
return "\\"+match
}
}).replace(/(\r\n|\n|\r)/g,"")+"\"";
if(i!=keys.length-1)
str+=","
})
str+="}";
return str;
function jsonToString(json, context) {
var str;
if (context) {
str = 'var ' + context.trim() + 'I18n={';
} else {
str = 'var i18n={';
}
var keys = Object.keys(json);
keys.forEach((key, i) => {
var value = json[key];
str +=
'"' +
key +
'":"' +
value
.replace(/.?\"/g, function(match) {
if (match[0] == '\\') {
return match;
} else if (match.length == 2) {
return match[0] + '\\' + match[1];
} else {
return '\\' + match;
}
})
.replace(/(\r\n|\n|\r)/g, '') +
'"';
if (i != keys.length - 1) str += ',';
});
str += '}';
return str;
}
export default function folderIterate(propertyFolder, i18nFolder, baseProperty, jsProperty){
export default function folderIterate(
propertyFolder,
i18nFolder,
baseProperty,
jsProperty,
context
) {
var basePropertyStr = fs.readFileSync(baseProperty).toString();
var basePropertyJson = stringToJson(basePropertyStr);
var jsPropertyStr = fs.readFileSync(jsProperty).toString();
var jsPropertyJson = stringToJson(jsPropertyStr);
var jsPropertyStr = fs.readFileSync(jsProperty).toString();
try {
var jsPropertyJson = JSON.parse(jsPropertyStr);
} catch (e) {
var jsPropertyJson = stringToJson(jsPropertyStr);
}
fs.readdir(propertyFolder, (err, files) => {
files.forEach(file => {
var location=path.join(propertyFolder,file);
if(fs.statSync(location).isDirectory()){
console.log("dir"+file)
}else{
if(location!=jsProperty && file.endsWith(".properties")){
var str = fs.readFileSync(location).toString()
var json=stringToJson(str)
var outputJson = Object.keys(jsPropertyJson).reduce((result,key)=>{
result[key]=json[key] || basePropertyJson[key] || jsPropertyJson[key];
fs.readdir(propertyFolder, function(err, files) {
files.forEach(function(file) {
var location = path.join(propertyFolder, file);
if (fs.statSync(location).isDirectory()) {
console.log('dir' + file);
} else {
if (
location != jsProperty &&
location != baseProperty &&
file.endsWith('.properties')
) {
var str = fs.readFileSync(location).toString();
var json = stringToJson(str);
var outputJson = Object.keys(jsPropertyJson).reduce(function(
result,
key
) {
result[key] =
json[key] || basePropertyJson[key] || jsPropertyJson[key];
return result;
},{})
var underScoreIndex = file.indexOf("_");
var outputFileName = "en_US.js";
if(underScoreIndex != -1){
outputFileName = file.substring(underScoreIndex+1,file.indexOf("."));
outputFileName += ".js";
}, {});
var underScoreIndex = file.indexOf('_');
var outputFileName = 'en_US.js';
if (underScoreIndex != -1) {
outputFileName = file.substring(
underScoreIndex + 1,
file.indexOf('.')
);
outputFileName += '.js';
}
console.log(file)
fs.writeFileSync(path.join(i18nFolder,outputFileName),jsonToString(outputJson));
console.log(file);
if (!fs.existsSync(i18nFolder)) {
fs.mkdir(i18nFolder);
}
fs.writeFileSync(
path.join(i18nFolder, outputFileName),
jsonToString(outputJson, context)
);
}
}
}
});
})
});
}

@@ -81,2 +118,2 @@

folderIterate(propertyFolder,i18nFolder, baseProperty, jsProperty);
*/
*/
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