{"id":24505714,"url":"https://github.com/ioncakephper/file-easy","last_synced_at":"2026-02-04T16:05:52.889Z","repository":{"id":57235418,"uuid":"306281966","full_name":"ioncakephper/file-easy","owner":"ioncakephper","description":"Working with the Node.js file system can be cumbersome. File-easy simplifies common file operations with a clean and easy-to-use API, making file management a breeze.","archived":false,"fork":false,"pushed_at":"2024-12-08T00:46:42.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T07:07:19.803Z","etag":null,"topics":["file-default-extension","file-helpers","file-manipulation","file-utils","file-write","filename-slug","save-files"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ioncakephper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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-10-22T09:07:08.000Z","updated_at":"2024-12-08T00:29:13.000Z","dependencies_parsed_at":"2025-01-21T23:31:29.074Z","dependency_job_id":"73a2656c-fe3d-4e82-9c57-0b4e713714fc","html_url":"https://github.com/ioncakephper/file-easy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncakephper%2Ffile-easy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncakephper%2Ffile-easy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncakephper%2Ffile-easy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncakephper%2Ffile-easy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ioncakephper","download_url":"https://codeload.github.com/ioncakephper/file-easy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837280,"owners_count":21169374,"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":["file-default-extension","file-helpers","file-manipulation","file-utils","file-write","filename-slug","save-files"],"created_at":"2025-01-21T23:31:19.087Z","updated_at":"2026-02-04T16:05:52.815Z","avatar_url":"https://github.com/ioncakephper.png","language":"JavaScript","readme":"# file-easy\n\nFile utilities to speed up creating document files, setting default extension, and getting a `slug` from a string.  `file-easy` provides a simple, lightweight, and easy-to-use set of functions for common file-related tasks. If you're tired of writing boilerplate code for handling filenames, creating text files, or generating URL-friendly slugs, `file-easy` simplifies these operations so you can focus on your core application logic. It's particularly well-suited for projects that frequently handle text files or need to sanitize filenames for web use.  No more complex regex or manual string manipulation – just clean, efficient file handling.\n\n[![npm](https://img.shields.io/npm/v/file-easy.svg)](https://www.npmjs.com/package/file-easy)\n[![npm](https://img.shields.io/npm/dm/file-easy.svg)](https://www.npmjs.com/package/file-easy)\n[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)\n[![Build Status](https://github.com/ioncakephper/file-easy/actions/workflows/node.js.yml/badge.svg)](https://github.com/ioncakephper/file-easy/actions/workflows/node.js.yml)\n[![njsscan sarif](https://github.com/ioncakephper/file-easy/actions/workflows/njsscan.yml/badge.svg)](https://github.com/ioncakephper/file-easy/actions/workflows/njsscan.yml)\n[![Node.js CI](https://github.com/ioncakephper/file-easy/actions/workflows/node.js.yml/badge.svg)](https://github.com/ioncakephper/file-easy/actions/workflows/node.js.yml)\n[![CodeQL Advanced](https://github.com/ioncakephper/file-easy/actions/workflows/codeql.yml/badge.svg)](https://github.com/ioncakephper/file-easy/actions/workflows/codeql.yml)\n[![DeepScan grade](https://deepscan.io/api/teams/15501/projects/18710/branches/463828/badge/grade.svg)](https://deepscan.io/dashboard#view=project\u0026tid=15501\u0026pid=18710\u0026bid=463828)\n\n## Installation\n\n```bash\nnpm i file-easy\n```\n\n## Usage\n\n### `.slug()`\n\n```javascript\nconst fileEasy = require('file-easy')\n\n// getting a slug\nlet fn = 'source Filename';\nlet slug = fileEasy.slug(fn)\nconsole.log('Slug:', slug)\n```\n\nWill show:\n\n```bash\nSlug: source-filename\n```\n\n```javascript\nconst fileEasy = require('file-easy')\n\nlet names = [\n    'Simple_File$Goes%Here',\n    '%%Welcome**    Buddy%\u0026^#$%'\n];\nnames.forEach((name) =\u003e {\n    console.log('Source: \"', name, '\" is:', fileEasy.slug(name))\n})\n```\n\nWill show:\n\n```bash\nSource: \" Simple_File$Goes%Here \" is: \" simple-file-goes-here\nSource: \" %%Welcome**    Buddy%\u0026^#$% \" is: \" welcome-buddy\n```\n\n### `.setDefaultExtension()`\n\n```javascript\nconst fileEasy = require('file-easy')\n\n// f1 is filename.js (no extension in original, apply extension)\nlet f1 = fileEasy.setDefaultExtension('filename', '.js)\n\n// f2 is filename.js (extension already exists)\nlet f2 = fileEasy.setDefaultExtension('filename.js', '.json')\n\n// f3 is filename. (extension starts with . in original)\nlet f3 = fileEasy.setDefaultExtension('filename.', '.js')\n```\n\n### `.saveDocument()`\n\n```javascript\nconst fileEasy = require('file-easy')\n\nlet filename = './docs/sample.txt'\nlet content = 'String to go in'\n\n/**\n * Creates the `sample.txt` file in `./docs` folder\n * If path does not exist, it will create it (e.g. `./docs`)\n * The file is saved as a utf-8 format (standard format)\n */\nfileEasy.saveDocument(filename, content)\n```\n\n## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#saveDocument\"\u003esaveDocument(filename, content)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eSave content in a file using utf8 format.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#setDefaultExtension\"\u003esetDefaultExtension(filename, extension)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eAppend specified extension if needed.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#slug\"\u003eslug(s)\u003c/a\u003e ⇒ \u003ccode\u003estring\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eConvert a string into an identifier.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"saveDocument\"\u003e\u003c/a\u003e\n\n## saveDocument(filename, content)\nSave content in a file using utf8 format.\n\n**Kind**: global function  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e If input is invalid or if there was an error during the save process.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| filename | \u003ccode\u003estring\u003c/code\u003e | The filename to create. It can also include a path ending with the filename. Path will be created if not exists. |\n| content | \u003ccode\u003estring\u003c/code\u003e | The content to place in the file. |\n\n\u003ca name=\"setDefaultExtension\"\u003e\u003c/a\u003e\n\n## setDefaultExtension(filename, extension) ⇒ \u003ccode\u003estring\u003c/code\u003e\nAppend specified extension if needed.\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - filename with either existing or specified extension  \n**Throws**:\n\n- \u003ccode\u003eTypeError\u003c/code\u003e If filename or extension is not a string.\n- \u003ccode\u003eError\u003c/code\u003e If extension is empty or doesn't start with a dot.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| filename | \u003ccode\u003estring\u003c/code\u003e | The filename to check for an existing extension. |\n| extension | \u003ccode\u003estring\u003c/code\u003e | The extension to append if filename has no extension. It should start with a dot (e.g. `.txt`) |\n\n\u003ca name=\"slug\"\u003e\u003c/a\u003e\n\n## slug(s) ⇒ \u003ccode\u003estring\u003c/code\u003e\nConvert a string into an identifier.\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - The identifier string.\n\nThe following operations are performed on the string:\n1. Trim and convert to lower case.\n2. Remove diacritics (transliterate or remove non-ASCII characters).\n3. Replace spaces and special characters with hyphens, allowing underscores.\n4. Replace multiple hyphens with a single hyphen.\n5. Remove leading and trailing hyphens.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| s | \u003ccode\u003estring\u003c/code\u003e | The string to convert. |\n\n## Author\n\n[Ion Gireada](https://github.com/ioncakephper) - shytiger[at]yahoo.com\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioncakephper%2Ffile-easy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fioncakephper%2Ffile-easy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioncakephper%2Ffile-easy/lists"}