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

ical2json

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ical2json - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test.js

155

index.js

@@ -1,82 +0,95 @@

(function() {
var NEW_LINE, convert, cwd, fs, path, run;
// Make sure lines are splited correctly
// http://stackoverflow.com/questions/1155678/javascript-string-newline-character
var NEW_LINE = /\r\n|\n|\r/,
path = require("path"),
fs = require("fs"),
cwd = process.cwd(),
convert, run, readFile;
fs = require("fs");
convert = function(source) {
var currentKey = "",
currentObj,
currentValue = "",
line,
objectNames = [],
output = {},
parentObj = {},
i,
linesLength,
lines = source.split(NEW_LINE),
splitAt;
path = require("path");
currentObj = output;
cwd = process.cwd();
for (i = 0, linesLength = lines.length; i < linesLength; i++) {
line = lines[i];
if (line.charAt(0) === " ") {
currentObj[currentKey] += line;
NEW_LINE = /\n\r?/;
} else {
splitAt = line.indexOf(":");
convert = function(source) {
var currentKey, currentObj, currentValue, line, objectNames, output, parentObj, _i, _len, _ref, _ref1;
output = {};
currentObj = output;
parentObj = {};
currentKey = "";
currentValue = "";
objectNames = [];
_ref = source.split(NEW_LINE);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
if (line.charAt(0) === " ") {
currentObj[currentKey] += line;
} else {
_ref1 = line.split(":"), currentKey = _ref1[0], currentValue = _ref1[1];
switch (currentKey) {
case "BEGIN":
parentObj = currentObj;
if (parentObj[currentValue] == null) {
parentObj[currentValue] = [];
}
currentObj = {};
parentObj[currentValue].push(currentObj);
break;
case "END":
currentObj = parentObj;
break;
default:
currentObj[currentKey] = currentValue;
}
if (splitAt < 0) {
continue;
}
}
return output;
};
run = function(options) {
var ext, file, filePath, files, stat, _i, _len, _results;
files = options.args || [];
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
filePath = path.resolve(cwd, file);
if (!fs.existsSync(filePath)) {
continue;
currentKey = line.substr(0, splitAt);
currentValue = line.substr(splitAt + 1);
switch (currentKey) {
case "BEGIN":
parentObj = currentObj;
if (parentObj[currentValue] == null) {
parentObj[currentValue] = [];
}
currentObj = {};
parentObj[currentValue].push(currentObj);
break;
case "END":
currentObj = parentObj;
break;
default:
currentObj[currentKey] = currentValue;
}
stat = fs.statSync(filePath);
ext = path.extname(filePath);
if (!(stat.isFile() && ext === ".ics")) {
continue;
}
_results.push(fs.readFile(filePath, function(error, buffer) {
var basename, dirname, output, writePath;
if (error != null) {
throw new Error(error);
}
output = convert(buffer.toString());
basename = path.basename(filePath, ext);
dirname = path.dirname(filePath);
writePath = path.join(dirname, basename) + ".json";
return fs.writeFile(writePath, JSON.stringify(output, null, " "));
}));
}
return _results;
};
}
return output;
};
module.exports = {
run: run,
convert: convert
};
run = function(options) {
var ext, file, filePath, files, stat, i, length;
files = options.args || [];
}).call(this);
for (i = 0, length = files.length; i < length; i++) {
file = files[i];
filePath = path.resolve(cwd, file);
if (!fs.existsSync(filePath)) {
continue;
}
stat = fs.statSync(filePath);
ext = path.extname(filePath);
if (!(stat.isFile() && ext === ".ics")) {
continue;
}
fs.readFile(filePath, function(error, buffer) {
var basename, dirname, output, writePath;
if (error != null) {
throw new Error(error);
}
output = convert(buffer.toString());
basename = path.basename(filePath, ext);
dirname = path.dirname(filePath);
writePath = path.join(dirname, basename) + ".json";
return fs.writeFile(writePath, JSON.stringify(output, null, " "));
});
}
};
module.exports = {
run: run,
convert: convert
};
{
"name": "ical2json",
"version": "0.1.2",
"version": "0.1.3",
"description": "A simple node package to convert ical to JSON",
"main": "index.js",
"scripts": {
"test": "grunt default"
"test": "grunt nodeunit"
},

@@ -31,7 +31,6 @@ "repository": {

"grunt": "~0.4.1",
"grunt-contrib-nodeunit": "~0.2.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-coffee": "~0.7.0",
"grunt-coffeelint": "0.0.7",
"matchdep": "~0.3.0"
"grunt-contrib-nodeunit": "~0.3.3",
"grunt-contrib-watch": "~0.6.1",
"matchdep": "~0.3.0",
"grunt-contrib-jshint": "~0.10.0"
},

@@ -38,0 +37,0 @@ "dependencies": {

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