Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Sep 28, 2022
1 parent bcec7ba commit 774b74a
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 15 deletions.
24 changes: 10 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ exports.editFile = function(path, options) {
* @param {String} path The path to the JSON file
* @param {String} data The data you would like to populate the file with
*/
exports.createFile = function(path, data = `{}`) {
exports.createFile = async(path, data = `{}`) => {
if (!path) {
throw new Error("ERROR with createFile: Path is null");
}
Expand All @@ -486,7 +486,7 @@ exports.createFile = function(path, data = `{}`) {
*
* @param {String} path The path to the JSON file
*/
exports.deleteFile = function(path) {
exports.deleteFile = async(path) => {
if (!path) {
throw new Error("ERROR with deleteFile: path is null");
}
Expand All @@ -505,7 +505,7 @@ exports.deleteFile = function(path) {
* @param {String} path The path to the JSON file
* @param {String} copyPath The path to the location you want the new file saved
*/
exports.copyFile = function(path, copyPath = null) {
exports.copyFile = async(path, copyPath = null) => {
if (!path) {
throw new Error("ERROR with copyFile: path is null");
}
Expand All @@ -530,7 +530,7 @@ exports.copyFile = function(path, copyPath = null) {
* @param {String} oldPath The path to the JSON file
* @param {String} newPath The path to the location you want to move the file
*/
exports.moveFile = function(oldPath, newPath) {
exports.moveFile = async(oldPath, newPath) => {
if (!oldPath) {
throw new Error("ERROR with moveFile: oldPath is null");
}
Expand All @@ -553,7 +553,7 @@ exports.moveFile = function(oldPath, newPath) {
* @param {String} path The path to the JSON file
* @param {String} newName The new name that will be set for the file
*/
exports.renameFile = function(path, newName) {
exports.renameFile = async(path, newName) => {
if (!path) {
throw new Error("ERROR with renameFile: path is null");
}
Expand All @@ -575,7 +575,7 @@ exports.renameFile = function(path, newName) {
* @param {String} path The path to the JSON file
* @returns {Object} The data from the file
*/
exports.readFile = function(path) {
exports.readFile = async(path) => {
if (!path) {
throw new Error("ERROR with readFile: path is null");
}
Expand All @@ -592,7 +592,7 @@ exports.readFile = function(path) {
* @param {"Map" | "Array"} format how the data will be presented (default: `Map`)
* @returns {Map} A map of the data from the files
*/
exports.readAllFiles = function(path, format = "Map") {
exports.readAllFiles = async(path, format = "Map") => {
if (!path) {
throw new Error("ERROR with readAllFiles: path is null");
}
Expand Down Expand Up @@ -631,7 +631,7 @@ exports.readAllFiles = function(path, format = "Map") {
* @param {String} path The path to the file
* @returns {Boolean}
*/
exports.fileExist = function(path) {
exports.fileExist = async(path) => {
if (!path) {
throw new Error("ERROR with fileExist: path is null");
}
Expand All @@ -644,13 +644,9 @@ exports.fileExist = function(path) {
* @param {String} path The path to the folder
* @returns {Boolean}
*/
exports.folderExist = function(path) {
exports.folderExist = async(path) => {
if (!path) {
throw new Error("ERROR with folderExist: path is null");
}
if (fs.existsSync(path)) {
return true;
} else {
return false
}
return fs.existsSync(path);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@acegoal07/json-editor",
"version": "1.1.0",
"description": "A simple json file editor",
"main": "index",
"main": "index.js",
"types": "types",
"repository": {
"type": "git",
"url": "git+https://github.com/acegoal07/json-editor.git"
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"include": ["index.js"],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "types",
"declarationMap": true
}
}
196 changes: 196 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
export function editFile(path: string, options: {
stringify_width?: number;
stringify_fn?: Function;
stringify_eol?: boolean;
ignore_dots?: boolean;
autosave?: boolean;
}): JsonEditor;
export function createFile(path: string, data?: string): Promise<void>;
export function deleteFile(path: string): Promise<void>;
export function copyFile(path: string, copyPath?: string): Promise<void>;
export function moveFile(oldPath: string, newPath: string): Promise<void>;
export function renameFile(path: string, newName: string): Promise<void>;
export function readFile(path: string): any;
export function readAllFiles(path: string, format?: "Map" | "Array"): Map;
export function fileExist(path: string): boolean;
export function folderExist(path: string): boolean;
/**
* The json editor
*
* @version `1.1.0`
* @author `acegoal07`
*
* @param {String} path
* @param {Object} options
*/
declare class JsonEditor {
constructor(path: any, options: any);
options: {};
path: any;
data: any;
/**
* Saves the file and any changes
*
* @param {Function} callback An optional callback function which will turn the function into an asynchronous one
* @returns {JsonEditor} The `JsonEditor` instance
*/
save(callback: Function): JsonEditor;
/**
* Get a value in a specific path
*
* @param {String} path The object path
* @returns {Anything} The object path value
*/
get(path: string): Anything;
/**
* Write the JSON file
*
* @param {String} content file content
* @param {Function} callback An optional callback function which will turn the function into an asynchronous one
* @returns {JsonEditor} The `JsonEditor` instance
*/
write(content: string, callback: Function): JsonEditor;
/**
* Copy's the data from a file into the file your editing
*
* @param {String} path The path to the JSON file
* @param {Boolean} layout The is used to add a layout out to the data being writen to the file
* @returns {JsonEditor} The `JsonEditor` instance
*/
writeCopy(path: string, layout?: boolean): JsonEditor;
/**
* Empty the JSON file content
*
* @param {Function} callback The callback function
*/
empty(callback: Function): JsonEditor;
/**
* Empty an arrays content
*
* @param {String} path The object path
*/
emptyArray(path: string): JsonEditor;
/**
* Empty an objects content
*
* @param {String} path The object path
*/
emptyObject(path: string): JsonEditor;
/**
* Read the JSON file
*
* @param {Function} callback An optional callback function which will turn the function into an asynchronous one
* @returns {Object} The object parsed as object or an empty object by default
*/
read(callback: Function): any;
/**
* Returns a object from the data path
*
* @returns {Object} The data object
*/
toObject(): any;
/**
* Returns a string of the json data
*
* @param {Boolean} keepLayout Weather or not the data should keep the object layout from the file
* @returns {String} The data string
*/
toString(keepLayout?: boolean): string;
/**
* Returns a joined string from the array path
*
* @param {String} path The object path
* @param {String} joiner The character to join the data with (default: `,`)
* @returns {String} The data string
*/
arrayToString({ path, joiner }: string): string;
/**
* Set a value in a specific path
*
* @param {String} path The object path
* @param {Anything} value The value
* @param {Object} options The options for set-value (applied only when {ignore_dots} file option is false)
* @returns {JsonEditor} The `JsonEditor` instance
*/
set(path: string, value: Anything, options: any): JsonEditor;
/**
* Remove a path from a JSON object
*
* @param {String} path The object path
* @returns {JsonEditor} The `JsonEditor` instance
*/
unset(path: string): JsonEditor;
/**
* Pushes the data to the top of the specified array
*
* @param {String} path The object path
* @param {Anything} value The value
* @returns {JsonEditor} The `JsonEditor` instance
*/
push(path: string, value: Anything): JsonEditor;
/**
* Switches a boolean data type between true and false
*
* @param {String} path The object path
* @returns {JsonEditor} The `JsonEditor` instance
*/
trigger(path: string): JsonEditor;
/**
* Pushes the data to the bottom of the specified array
*
* @param {String} path The object path
* @param {Anything} value The value
* @returns {JsonEditor} The `JsonEditor` instance
*/
unshift(path: string, value: Anything): JsonEditor;
/**
* Remove the last item from an array
*
* @param {String} path The object path
* @returns {JsonEditor} The `JsonEditor` instance
*/
popLast(path: string): JsonEditor;
/**
* Removes a specific item from an array
*
* @param {String} path The object path
* @param {Number} position The position of the item
* @returns {JsonEditor} The `JsonEditor` instance
*/
popTo(path: string, position: number): JsonEditor;
/**
* Remove the first item from an array
*
* @param {String} path The object path
* @returns {JsonEditor} The `JsonEditor` instance
*/
popFirst(path: string): JsonEditor;
/**
* Gets the keys of data from the
*
* @param {String} path An optional setting to get keys from a path
* @returns {Array} The keys
*/
getKeys(path?: string): any[];
/**
* Deletes the file that's being edited
*/
delete(): Promise<void>;
/**
* Copy's the data from one path to a another
*
* @param {String} path The object path to the data you want to copy
* @param {String} copyPath The object path to the place you wanna put the data
* @returns {JsonEditor} The `JsonEditor` instance
*/
copy(path: string, copyPath: string): JsonEditor;
/**
* Moves the data to a new path and deletes the original
*
* @param {String} oldPath The object path to the data you want to move
* @param {String} newPath The object path to the place you wanna put the data
* @returns {JsonEditor} The `JsonEditor` instance
*/
move(oldPath: string, newPath: string): JsonEditor;
}
export {};

0 comments on commit 774b74a

Please sign in to comment.