{"id":20256318,"url":"https://github.com/devcybiko/glsfiles","last_synced_at":"2025-03-03T17:54:55.505Z","repository":{"id":35196944,"uuid":"212470433","full_name":"devcybiko/glsfiles","owner":"devcybiko","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-24T01:29:11.000Z","size":5430,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T13:10:00.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devcybiko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-03T00:47:27.000Z","updated_at":"2020-05-16T07:35:21.000Z","dependencies_parsed_at":"2023-02-13T09:01:24.711Z","dependency_job_id":null,"html_url":"https://github.com/devcybiko/glsfiles","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglsfiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglsfiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglsfiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglsfiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devcybiko","download_url":"https://codeload.github.com/devcybiko/glsfiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241715023,"owners_count":20007913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T10:46:12.984Z","updated_at":"2025-03-03T17:54:55.486Z","avatar_url":"https://github.com/devcybiko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# glsfiles\n\nThis is a collection of 'useful' file-io methods I use over and over again. They aren't particularly well-written, but are good for quick file-io solutions or examples.\n\nAll calls are synchronous.\n\nNOTE: There's not much error processing done here. Pretty much any failing `read` operation returns an empty String, Object, or Array. Any failing `write` operation will likely throw an exception (so you should wrap `write` operations with `try/catch` if you care about exceptions).\n\n## readFile: function (fname) : String\n\nRead the file as one long string of text\n\n## readTextFile: function (fname) : String[]\n\nReads the file and returns each line as a string in the array.\n\n## readListFile: function (fname) : String[]\n\nJust like readTextFile but filters out blank lines and lines beginning with '#' signs (comments)\n\n## readJSONFile: function (fname) : Object\n\nReads the file and calls JSON.parse on the results and returns a JavaScript object.\n\n## readJSONCFile: function (fname) : Object\n\nSuper simplistic JSONC reader. Not very bright.\n\nSame as readJSONFile but filters out any comments (`//`). \n\nNOTE: It gets confused if the file contains URLS with full domain specs (eg: http://google.com - because the `//` looks like a comment). Or if `//` appears on the values.\n\n## readCSVFile: function (CSVFname) : Object[]\n\nSuper simplistic CSV file reader. Not very bright. Doesn't handle quoted values in columns, for example. Also, doesn't handle commas as a character in the field (it would split the field into two colums).\n\nReads a file that is formatted as a CSV. Assumes the first row is the header and subsequent rows are comma-separated.\n\nReturns an array of 'objects' with key/value pairs such that each key is a column name from the header.\n\n## readRegExpFile: function (fname) : String[]\n\nPerforms a `readListFile` on `fname` and returns a list of JavaScript regular expressions. (This may seem like a very unique use case, but it is good for a file of whitelist or blacklist names).\n\n## writeTextFile: function (fname, list) : undefined\n\nThe converse of `readTextFile`, takes a list of strings and writes them to a file (separated by newlines).\n\nNOTE: creates all intermediary directories up to the filename.\n\n## writeFile: function (fname, str) : undefined\n\nThe converse of `readFile`, takes a single string and writes it to a file.\n\nNOTE: creates all intermediary directories up to the filename\n\n## createFile: function (fname) : undefined\n\nCreates (or overwrites) an empty file onto `fname`.\n\nNOTE: creates all intermediary directories up to the filename.\n\n## createDir: function (dirname) : undefined\n\nCreates the directory specified by `dirname`\n\nNOTE: creates all intermediary directories up to the dirname.\n\n## readDir: function (dirname) : String[]\n\nReads the specified directory and returns an array of strings, each one a file/directory in the specified directory.\n\nNOTE: Includes all 'dot' files (those beginning with a period) including the current (.) and previous (..) directories. Does not include the directory name leading up to the filenames.\n\nNOTE: Use [fs.statSync](https://nodejs.org/api/fs.html#fs_fs_statsync_path_options) to determine if a file is a regular file or directory.\n\n## run: function (cmd) : String\n\nRuns the `bash` command on the supplied `cmd` and returns the results from `stdout` as one long string. (NOTE: You and use `.split()` to break the results into an array of lines). Also, if there is an error `stderr` is returned instead without warning. You'll have to somehow parse the returned string to determine if things went well or not\n\n## Usage\n\n```javascript\nconst gls = require('glsfiles');\n...\n\tgls.writeFile(\"grades.json\", JSON.stringify(data));\n...\n    var json = gls.readJSONFile(fname);\n    console.log(json.someField);\n...\n    var lines = gls.readTextFile(infname);\n    for(let i=0; i\u003clines.length; i++) console.log(lines[i]);\n    lines.map(line =\u003e console.log(line));\n...\n    // file looks like this...\n    // name,week,assignment,grade\n    // GSmith,1,Project 1,A\n    // HJones,2,Project 2,B\n    var rows = gls.readCSVFile(csvFname);\n    \n    console.log(rows[0].name); //output =\u003e GSmith\n    console.log(rows[0].week); //output =\u003e 1\n    console.log(rows[0].assignment); //output =\u003e Project 1\n    console.log(rows[0].grade); //output =\u003e A\n\n    console.llg(rows[1].name); // output =\u003e HJones\n    console.llg(rows[1].week); // output =\u003e 2\n    console.llg(rows[1].assignment); // output =\u003e Project 2\n    console.llg(rows[1].grade); // output =\u003e B\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevcybiko%2Fglsfiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevcybiko%2Fglsfiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevcybiko%2Fglsfiles/lists"}