{"id":20256218,"url":"https://github.com/devcybiko/glstools","last_synced_at":"2025-10-14T09:36:56.955Z","repository":{"id":48425017,"uuid":"264751525","full_name":"devcybiko/glstools","owner":"devcybiko","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-21T23:03:18.000Z","size":6480,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-11T10:13:58.296Z","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-17T20:31:35.000Z","updated_at":"2024-04-21T23:03:22.000Z","dependencies_parsed_at":"2024-04-22T00:22:14.707Z","dependency_job_id":"d2f07371-78d6-4265-81cd-677726888af0","html_url":"https://github.com/devcybiko/glstools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devcybiko/glstools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglstools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglstools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglstools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglstools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devcybiko","download_url":"https://codeload.github.com/devcybiko/glstools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devcybiko%2Fglstools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018620,"owners_count":26086404,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:45:53.830Z","updated_at":"2025-10-14T09:36:56.939Z","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%2Fglstools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevcybiko%2Fglstools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevcybiko%2Fglstools/lists"}