{"id":22645395,"url":"https://github.com/heliomarpm/helpers","last_synced_at":"2025-04-18T03:10:36.279Z","repository":{"id":193143827,"uuid":"631371224","full_name":"heliomarpm/helpers","owner":"heliomarpm","description":"A utility for NodeJS App with many useful features","archived":false,"fork":false,"pushed_at":"2025-03-24T18:17:07.000Z","size":413,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T19:24:55.711Z","etag":null,"topics":["cache","cache-storage","electron-app","helpers","library","memory","memory-storage","node-js","utility-library","utils"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@heliomarpm/helpers","language":"TypeScript","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/heliomarpm.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}},"created_at":"2023-04-22T20:12:44.000Z","updated_at":"2025-03-24T18:17:11.000Z","dependencies_parsed_at":"2023-09-07T00:27:50.210Z","dependency_job_id":"e6fcad6d-7aab-4ad2-97ab-2e02799fa593","html_url":"https://github.com/heliomarpm/helpers","commit_stats":null,"previous_names":["heliomarpm/helpers"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliomarpm%2Fhelpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliomarpm%2Fhelpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliomarpm%2Fhelpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliomarpm%2Fhelpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heliomarpm","download_url":"https://codeload.github.com/heliomarpm/helpers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249418520,"owners_count":21268448,"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":["cache","cache-storage","electron-app","helpers","library","memory","memory-storage","node-js","utility-library","utils"],"created_at":"2024-12-09T06:05:24.908Z","updated_at":"2025-04-18T03:10:36.247Z","avatar_url":"https://github.com/heliomarpm.png","language":"TypeScript","funding_links":["https://ko-fi.com/heliomarpm","https://liberapay.com/heliomarpm","https://github.com/sponsors/heliomarpm"],"categories":[],"sub_categories":[],"readme":"\u003cdiv id=\"top\" align=\"center\" style=\"text-align:center;\"\u003e\r\n\u003ch1\u003e\r\n  \u003cimg src=\"logo.png\" alt=\"Helpers Library\" width=\"128\" /\u003e\r\n  \u003cbr\u003eHelpers Library\r\n  \u003ca href=\"https://navto.me/heliomarpm\" target=\"_blank\"\u003e\u003cimg src=\"https://navto.me/assets/navigatetome-brand.png\" width=\"32\"/\u003e\u003c/a\u003e\r\n\r\n  [![DeepScan grade][url-deepscan-badge]][url-deepscan]\r\n  [![CodeFactor][url-codefactor-badge]][url-codefactor] \r\n  ![CodeQL][url-codeql]\u003c!-- ![Publish][url-publish] --\u003e [![NPM version][url-npm-badge]][url-npm]\r\n  [![Downloads][url-downloads-badge]][url-downloads]\r\n  \r\n  \u003c!-- ![lodash](https://img.shields.io/github/package-json/dependency-version/heliomarpm/helpers/lodash)   --\u003e\r\n\u003c/h1\u003e\r\n\r\n\u003cp\u003e\r\n  \u003c!-- PixMe --\u003e\r\n  \u003ca href=\"https://www.pixme.bio/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"pixme url\" src=\"https://img.shields.io/badge/donate%20on-pixme-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=28f4f4\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- PayPal --\u003e\r\n  \u003ca href=\"https://bit.ly/paypal-sponsor-heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"paypal url\" src=\"https://img.shields.io/badge/paypal-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=0475fe\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- Ko-fi --\u003e\r\n  \u003ca href=\"https://ko-fi.com/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"kofi url\" src=\"https://img.shields.io/badge/kofi-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=ff5f5f\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- LiberaPay --\u003e  \r\n  \u003ca href=\"https://liberapay.com/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n     \u003cimg alt=\"liberapay url\" src=\"https://img.shields.io/badge/liberapay-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=f6c915\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- Version --\u003e\r\n  \u003c!-- \u003ca href=\"https://github.com/heliomarpm/helpers/releases\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n     \u003cimg alt=\"releases url\" src=\"https://img.shields.io/github/v/release/heliomarpm/helpers?style=for-the-badge\u0026labelColor=1C1E26\u0026color=2ea043\"/\u003e\r\n  \u003c/a\u003e   --\u003e\r\n  \u003c!-- License --\u003e\r\n  \u003c!-- \u003ca href=\"https://github.com/heliomarpm/helpers/blob/main/LICENSE\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"license url\" src=\"https://img.shields.io/badge/license%20-MIT-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=61ffca\"/\u003e\r\n  \u003c/a\u003e --\u003e\r\n\u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n\r\n## 🎯 About\r\n\r\n`@heliomarpm/helpers` is a comprehensive collection of TypeScript utility functions for formatting, type checking, conversion, and general utilities. This library provides a set of helper functions to make common programming tasks easier and more maintainable.\r\n\r\n\r\n## 🚀 Features\r\n\r\n- Type checking utilities (is.ts)\r\n- String and data formatting helpers (format.ts) \r\n- Type conversion functions (to.ts)\r\n- General utility functions (utils.ts)\r\n- Fully typed with TypeScript\r\n- Zero dependencies\r\n- Tree-shakeable exports\r\n- CommonJS and ES Module support\r\n\r\n## 📁 Project structure:\r\n\r\n```\r\nsrc/\r\n├── helpers/\r\n│   ├── format.ts    # Formatting utilities\r\n│   ├── is.ts        # Type checking functions\r\n│   ├── to.ts        # Type conversion helpers\r\n│   └── utils.ts     # General utilities\r\n└── index.ts         # Main entry point\r\n```\r\n\r\n\r\n\r\n## 📦 Installation\r\n\r\nYou can install the library using `npm` or `yarn`:\r\n\r\n```bash\r\nnpm i @heliomarpm/helpers\r\n# or \r\nyarn add @heliomarpm/helpers\r\n```\r\n\r\n## 🔧 Basic Usage\r\n\r\nTo use the library in a TypeScript or modern JavaScript project, you can import it directly:\r\n\r\n```typescript\r\nimport { Is, To, Format, Utils } from '@heliomarpm/helpers';\r\n\r\n// Type checking\r\nIs.CPF('111.222.333-00'); // false\r\nIs.CNPJ('11.222.333/0001-00'); // false\r\n\r\n// Conversion\r\nTo.boolean('1'); // true\r\nTo.boolean('false'); // false\r\nTo.boolean('invalid'); // false\r\n\r\n// Formatting\r\nFormat.date('2025-03-02', 'dddd, dd mmmm yyyy', 'en-US'); // \"Sunday, 02 March 2025\"\r\nFormat.ptBr.valorPorExtenso(100_000); // \"cem mil\"\r\n\r\n// General utilities\r\nUtils.getNestedValue({ user: { name: { first: 'John' } }}, \"user.name.first\"); // \"John\"\r\n\r\nconst target = {user: {name: {first: 'John',last: 'Doe'} } };\r\n\r\nUtils.setNestedValue(target, \"user.name.first\", \"Jane\"); \r\nUtils.setNestedValue(target, 'user.name.first', 'Jane');\r\nUtils.setNestedValue(target, 'children[0].name', 'John');\r\nUtils.setNestedValue(target, 'animals[0]', 'dog');\r\nUtils.setNestedValue(target, 'animals[1]', 'cat');\r\n\r\n// output will be target:\r\n{ \r\n  user: { name: { first: 'Jane', last: 'Doe' } }, \r\n  children: [{ name: 'John' }], \r\n  animals: ['dog', 'cat'] \r\n}\r\n\r\n```\r\n\r\n## Main functionalities\r\n\r\n### Usage\r\n\r\n```typescript\r\nimport { Format, Is, To, Utils } from '@heliomarpm/helpers';\r\n```\r\n\r\n### Format Helpers\r\n\r\n#### Brazilian Formats (ptBr)\r\n\r\n```typescript\r\nFormat.ptBr.cnpj('12345678901234'); // Formatar CNPJ '12.345.678/9012-34'\r\nFormat.ptBr.cnpj('1234567890123400', 'CNPJ não pode ser formatado'); // 'CNPJ não pode ser formatado'\r\n\r\nFormat.ptBr.cpf('12345678901'); // '123.456.789-01'\r\nFormat.ptBr.cpf('1234567890100', 'CPF não pode ser formatado'); // 'CPF não pode ser formatado'\r\n\r\nFormat.ptBr.cep('12345678'); // '12345-678'\r\nFormat.ptBr.cep('1234567800', 'CEP não pode ser formatado'); // 'CEP não pode ser formatado'\r\n\r\nFormat.ptBr.telefone('11999999999'); // '11 99999-9999'\r\nFormat.ptBr.telefone('1199999999900', 'Telefone não pode ser formatado'); // 'Telefone não pode ser formatado'\r\nFormat.ptBr.valorPorExtenso(1234); // 'mil duzentos e trinta e quatro'\r\n```\r\n\r\n#### Date Formatting\r\n\r\n```typescript\r\nFormat.date(new Date(), 'dd/mm/yyyy HH:MM:ss'); // '31/12/2023 23:59:59'\r\nFormat.date('2025-03-02', 'dddd, dd mmmm yyyy', 'en-US'); // \"Sunday, 02 \r\n```\r\n\r\n###### Supported formats are:\r\n\r\n```js\r\n/**\r\n * @param {string} format - The desired format for the output string.\r\n * - 'a': 'am' or 'pm' in lowercase\r\n * - 'A': 'AM' or 'PM' in uppercase\r\n * - 'hh': two-digit hours in 12h format (01-12)\r\n * - 'h': hours in 12h format (1-12)\r\n * - 'HH': two-digit hours in 24h format (00-23)\r\n * - 'H': hours in 24h format (0-23)\r\n * - 'MM': two-digit minutes (00-59)\r\n * - 'ss': two-digit seconds (00-59)\r\n * - 'SSS': three-digit milliseconds (000-999)\r\n * - 'yyyy': four-digit year (2024)\r\n * - 'yy': two-digit year (24)\r\n * - 'mmmm': full month name (January, February, ...)\r\n * - 'mmm': full month name abbreviated month (Jan, Feb, ...)\r\n * - 'mm': two-digit month (01-12)\r\n * - 'dddd': full weekday name (Sun, Mon, ...)\r\n * - 'ddd': abbreviated weekday name (Sun, Mon, ...)\r\n * - 'dd': two-digit day (01-31)\r\n */\r\n  ```\r\n\r\n\r\n#### Number Formatting\r\n\r\n```typescript\r\n// Format currency\r\nFormat.currency(1234.56, { locale: 'en', currency: 'USD' }); // '$1,234.56'\r\n\r\n// Formating number (1.234,56)\r\nFormat.number(1234.56); // '1.234,56'\r\n\r\n// Abreviate number (1.23K, 1.23M, etc.)\r\nFormat.abbreviateNumber(1234567); // '1.23M'\r\n\r\n// Remove non-numeric characters from a string.\r\nFormat.onlyNumbers('abc123'); // '123'\r\n\r\n// Pads a number with leading zeros to match the number of digits in a given maximum value\r\nFormat.padZerosByRef(5, 100); // '005'\r\n\r\n#### String Formatting\r\n\r\n// Capitalizes the first letter of a string\r\nFormat.titleCase('john doe'); // 'John Doe'\r\nFormat.titleCase('MARIA DA SILVA'); // 'Maria da Silva'\r\n\r\n// Mask a part of a string with a single character\r\nFormat.maskIt('1234567890', 3, 6, '*'); // '123****890'\r\n```\r\n\r\n### Is Helpers (Validation)\r\n\r\n```typescript\r\nIs.cpf('123.456.789-01'); // Validates CPF\r\nIs.cnpj('12.345.678/9012-34'); // Validates CNPJ\r\nIs.numeric('123'); // true\r\nIs.equals(obj1, obj2); // Deep comparison\r\nIs.date('2023-12-31'); // Validates date\r\nIs.nullOrEmpty(value); // Checks for null/empty\r\nIs.object({}); // Validates object type\r\nIs.email('user@example.com'); // Validates email\r\n\r\n// OS and Architecture checks\r\nIs.windowsOS\r\nIs.linuxOS\r\nIs.macOS\r\nIs.arch_x86\r\nIs.arch_x64\r\nIs.arch_Arm\r\nIs.arch_Arm64\r\n```\r\n\r\n### To Helpers (Conversion)\r\n\r\n```typescript\r\nTo.dictionary(jsonObject); // Converts to Record\u003cstring, T\u003e\r\nTo.boolean('true'); // Converts to boolean\r\nTo.dateParts(new Date()); // Extracts date components\r\nTo.number('123'); // Converts to number\r\n```\r\n\r\n### Utils Helpers\r\n\r\n```typescript\r\nUtils.gerarCPF(); // Generates valid CPF\r\nUtils.gerarCNPJ(); // Generates valid CNPJ\r\nUtils.sortByProps(['name', '-age']); // Sort function for arrays\r\nUtils.orderBy(array, 'key', 'asc'); // Sort array by key\r\nUtils.getNestedValue(obj, 'user.name'); // Get nested object value\r\nUtils.setNestedValue(obj, 'user.name', value); // Set nested object value\r\nUtils.ifNull(value, defaultValue); // Null coalescing\r\nUtils.ifNullOrEmpty(value, value2, defaultValue); // Returns the first non-null, non-undefined, and non-empty value from the given arguments.\r\nUtils.generateGuid(); // Generate GUID (e.g. '00000000-0000-0000-0000-000000000000') \r\nUtils.months({locale: 'pt-BR', month: 'long'}); // Get month names array (e.g. ['Janeiro', 'Fevereiro', ...])\r\nUtils.weekdays({locale: 'pt-BR', weekday: 'long'}); // Get weekday names array (e.g. ['Domingo', 'Segunda-feira', ...])\r\n\r\n// Crypto utilities\r\nUtils.crypto.generateKey(); // Generate encryption key\r\nUtils.crypto.encrypt(text, key); // Encrypt text\r\nUtils.crypto.decrypt(encryptedText, key); // Decrypt text\r\n```\r\n\r\n## Dependencies\r\n\r\n  This library has no dependencies\r\n\r\n\r\n## 🤝 Contributing\r\n\r\nPlease make sure to read the [Contributing Guide](docs/CONTRIBUTING.md) before making a pull request.\r\n\r\n\r\nThank you to all the people who already contributed to project!\r\n\r\n\u003ca href=\"https://github.com/heliomarpm/helpers/graphs/contributors\" target=\"_blank\"\u003e\r\n  \u003cimg src=\"https://contrib.rocks/image?repo=heliomarpm/helpers\" /\u003e\r\n\u003c/a\u003e\r\n\r\n###### Made with [contrib.rocks](https://contrib.rocks).\r\n\r\nThat said, there's a bunch of ways you can contribute to this project, like by:\r\n\r\n- :beetle: Reporting a bug\r\n- :page_facing_up: Improving this documentation\r\n- :rotating_light: Sharing this project and recommending it to your friends\r\n- :dollar: Supporting this project on GitHub Sponsors or Ko-fi\r\n- :star2: Giving a star on this repository\r\n\r\n\r\n## 📢 Support the Project\r\n\r\nIf you appreciate that, please consider donating to the Developer.\r\n\r\n\u003cp\u003e\r\n  \u003c!-- PixMe --\u003e\r\n  \u003ca href=\"https://www.pixme.bio/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"pixme url\" src=\"https://img.shields.io/badge/donate%20on-pixme-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=28f4f4\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- PayPal --\u003e\r\n  \u003ca href=\"https://bit.ly/paypal-sponsor-heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"paypal url\" src=\"https://img.shields.io/badge/paypal-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=0475fe\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- Ko-fi --\u003e\r\n  \u003ca href=\"https://ko-fi.com/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"kofi url\" src=\"https://img.shields.io/badge/kofi-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=ff5f5f\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003c!-- LiberaPay --\u003e  \r\n  \u003ca href=\"https://liberapay.com/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n     \u003cimg alt=\"liberapay url\" src=\"https://img.shields.io/badge/liberapay-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=f6c915\"/\u003e\r\n  \u003c/a\u003e  \r\n  \u003c!-- GitHub Sponsors --\u003e\r\n  \u003ca href=\"https://github.com/sponsors/heliomarpm\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\r\n    \u003cimg alt=\"github sponsors url\" src=\"https://img.shields.io/badge/GitHub%20-Sponsor-1C1E26?style=for-the-badge\u0026labelColor=1C1E26\u0026color=db61a2\"/\u003e\r\n  \u003c/a\u003e\r\n\u003c/p\u003e\r\n\r\n## 📝 License\r\n\r\n[MIT © Heliomar P. Marques](LICENSE) \u003ca href=\"#top\"\u003e🔝\u003c/a\u003e\r\n\r\n----\r\n[url-npm]: https://www.npmjs.com/package/@heliomarpm/helpers\r\n[url-npm-badge]: https://img.shields.io/npm/v/@heliomarpm/helpers.svg\r\n[url-downloads]: http://badge.fury.io/js/@heliomarpm/helpers.svg\r\n[url-downloads-badge]: https://img.shields.io/npm/dm/@heliomarpm/helpers.svg  \r\n[url-deepscan]: https://deepscan.io/dashboard#view=project\u0026tid=19612\u0026pid=28935\u0026bid=933374\r\n[url-deepscan-badge]: https://deepscan.io/api/teams/19612/projects/28935/branches/933374/badge/grade.svg\r\n[url-codefactor]: https://www.codefactor.io/repository/github/heliomarpm/helpers\r\n[url-codefactor-badge]: https://www.codefactor.io/repository/github/heliomarpm/helpers/badge\r\n[url-codeql]: https://github.com/heliomarpm/helpers/actions/workflows/codeql.yml/badge.svg \r\n[url-publish]: https://github.com/heliomarpm/helpers/actions/workflows/publish.yml/badge.svg\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheliomarpm%2Fhelpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheliomarpm%2Fhelpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheliomarpm%2Fhelpers/lists"}