Skip to content

Commit

Permalink
fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
hosein2398 committed Sep 11, 2017
1 parent 1d308a8 commit 52df967
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/2do.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ function todoMain() {
}
if (wantedFileObj && wantedFileObj[args.todoNumber]) {
delete todoObj[args.fileName][args.todoNumber];
Object.prototype.renameProperty = function (oldName, newName) {
if (oldName == newName) {
return this;
}
if (this.hasOwnProperty(oldName)) {
this[newName] = this[oldName];
delete this[oldName];
}
return this;
};
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
var theyKeys = Object.keys(todoObj[args.fileName]);
for (var i = 1; i <= Object.size(todoObj[args.fileName]); i++) {
if (theyKeys[i-1] > args.todoNumber) {
todoObj[args.fileName].renameProperty(theyKeys[i-1], theyKeys[i-1] - 1);
}
}
fs.writeFile('2do.json', JSON.stringify(todoObj), (err) => {
if (err) throw err;
console.log('The file has been saved!');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "2do-cli",
"version": "1.0.28",
"version": "1.0.29",
"description": "",
"main": "./lib/2do.js",
"scripts": {
Expand Down

0 comments on commit 52df967

Please sign in to comment.