{"id":18406366,"url":"https://github.com/magynhard/lucky-case","last_synced_at":"2025-04-07T08:32:22.575Z","repository":{"id":112989614,"uuid":"315103221","full_name":"magynhard/lucky-case","owner":"magynhard","description":"The lucky javascript library to identify and convert strings from any letter case to another","archived":false,"fork":false,"pushed_at":"2024-07-17T16:07:14.000Z","size":332,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T11:54:05.000Z","etag":null,"topics":["capitalize","case","convert-strings","converter","dash-case","javascript","letter-case","lower-case","node-js","npm-module","npm-package","pascal-case","recognizer","snake-case","string-transformations","transformer","upper-case","utf-8"],"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/magynhard.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-11-22T18:18:24.000Z","updated_at":"2024-07-17T16:07:17.000Z","dependencies_parsed_at":"2023-06-19T00:06:32.901Z","dependency_job_id":null,"html_url":"https://github.com/magynhard/lucky-case","commit_stats":{"total_commits":35,"total_committers":2,"mean_commits":17.5,"dds":0.02857142857142858,"last_synced_commit":"e4316ab1fadb3af9f614386cb4e8a1346b2ecd7d"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magynhard%2Flucky-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magynhard%2Flucky-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magynhard%2Flucky-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magynhard%2Flucky-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magynhard","download_url":"https://codeload.github.com/magynhard/lucky-case/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247620398,"owners_count":20968202,"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":["capitalize","case","convert-strings","converter","dash-case","javascript","letter-case","lower-case","node-js","npm-module","npm-package","pascal-case","recognizer","snake-case","string-transformations","transformer","upper-case","utf-8"],"created_at":"2024-11-06T03:08:39.707Z","updated_at":"2025-04-07T08:32:22.102Z","avatar_url":"https://github.com/magynhard.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lucky-case\n[![npm package](https://img.shields.io/npm/v/lucky-case?color=default\u0026style=plastic\u0026logo=npm\u0026logoColor=red)](https://www.npmjs.com/package/lucky-case)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/magynhard/lucky-case?color=default\u0026label=browser\u0026logo=javascript\u0026style=plastic)](https://github.com/magynhard/lucky-case/releases)\n![downloads](https://img.shields.io/npm/dt/lucky-case?color=blue\u0026style=plastic)\n[![License: MIT](https://img.shields.io/badge/License-MIT-gold.svg?style=plastic\u0026logo=mit)](LICENSE)\n\n\u003e The lucky javascript library to identify and convert strings from any letter case to another. Plus some extra functions.\n\nIt's a port of my ruby gem [lucky_case](https://github.com/magynhard/lucky_case).\n\nUseful when working with conventions, where class names, method names and file names needs to be converted.\n\n* Converters: Only characters, numbers, dashes and underlines are allowed inside a string.\n* Must not start with dash or number, underlines at the beginning are allowed by default and can be allowed/removed/controlled by parameter (when used for private methods for example)\n\n### Support for UTF-8 / Unicode\nAs JavaScript has no unicode regular expression support like Ruby, UTF-8/Unicode-Ranges for non-latin letters have been included,\nto ensure proper case detection.\n\nThis functionality has not been extensively tested and is therefore experimental in nature.\n\n# Contents\n\n* [Usage](#usage)\n* [Installation](#installation)\n* [Documentation](#documentation)\n* [Contributing](#contributing)\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\n\nYou can either use the static LuckyCase class with its method or optionally monkey patch the String class.\n\n### Approach 1: Using the static class\n```javascript\n// node js\nconst LuckyCase = require('lucky-case');\n// browser\n\u003cscript type=\"text/javascript\" src=\"js/lib/lucky-case.min.js\"\u003e\u003c/script\u003e\n\n// converters\nLuckyCase.toSnakeCase('PascalToSnake')                  // =\u003e 'pascal_to_snake'\nLuckyCase.toUpperSnakeCase('Train-To-Upper-Snake')      // =\u003e 'TRAIN_TO_UPPER_SNAKE'\nLuckyCase.toPascalCase('snake_to_pascal')               // =\u003e 'SnakeToPascal'\nLuckyCase.toCamelCase('dash-to-camel-case')             // =\u003e 'dashToCamelCase'\nLuckyCase.toDashCase('PascalToDashCase')                // =\u003e 'pascal-to-dash-case'\nLuckyCase.toUpperDashCase('PascalToUpperDash')          // =\u003e 'PASCAL-TO-UPPER-DASH'\nLuckyCase.toTrainCase('snake_to_train_case')            // =\u003e 'Snake-To-Train-Case'\nLuckyCase.toWordCase('PascalToWordCase')                // =\u003e 'pascal to word case'\nLuckyCase.toUpperWordCase('PascalToUpperWord')          // =\u003e 'PASCAL TO UPPER WORD'\nLuckyCase.toCapitalWordCase('snake_to_capital_word')    // =\u003e 'Snake To Capital Word'\nLuckyCase.toSentenceCase('snake_to_sentence_case')      // =\u003e 'Snake to sentence case'\nLuckyCase.toMixedCase('example_snake_string')           // =\u003e 'Example-snake_STRING'\n\n// converter by type\nLuckyCase.convertCase('some_snake', 'PASCAL_CASE')      // =\u003e 'SomeSnake'\n\n// transformers\nLuckyCase.toLowerCase('Some_FuckingShit')               // =\u003e 'some_fuckingshit'\nLuckyCase.toUpperCase('Some_FuckingShit')               // =\u003e 'SOME_FUCKINGSHIT'\nLuckyCase.toCapital('example')                          // =\u003e 'Example'\nLuckyCase.capitalize('exAmple')                         // =\u003e 'ExAmple'\nLuckyCase.decapitalize('ExAmple')                       // =\u003e 'exAmple'\nLuckyCase.swapCase('SomeSwappy_Case-Example')           // =\u003e 'sOMEsWAPPY-cASE_eXAMPLE'\nLuckyCase.constantize('some_constant')                  // =\u003e SomeConstant\nLuckyCase.constantize('SOME_CONSTANT')                  // =\u003e SomeConstant\nLuckyCase.constantize('some/path_example/folder')       // =\u003e SomePathExampleFolder\nLuckyCase.deconstantize(SomeConstant)                   // =\u003e 'someConstant' // default caseType: 'CAMEL_CASE'\nLuckyCase.deconstantize(SomeConstant, caseType: 'SNAKE_CASE')  // =\u003e 'some_constant'\n\n// identifiers\nLuckyCase.case('this_can_only_be_snake_case')           // =\u003e 'SNAKE_CASE'\nLuckyCase.cases('validformultiple')                     // =\u003e [ 'SNAKE_CASE', 'CAMEL_CASE', 'DASH_CASE', 'WORD_CASE' ]\n\n// checkers\nLuckyCase.isSnakeCase('valid_snake_case')               // =\u003e true\nLuckyCase.isUpperSnakeCase('UPPER_SNAKE')               // =\u003e true\nLuckyCase.isPascalCase('PascalCase')                    // =\u003e true\nLuckyCase.isCamelCase('toCamelCase')                    // =\u003e true\nLuckyCase.isDashCase('dash-case')                       // =\u003e true\nLuckyCase.isUpperDashCase('DASH-CASE')                  // =\u003e true\nLuckyCase.isTrainCase('Train-Case')                     // =\u003e true\nLuckyCase.isWordCase('word case')                       // =\u003e true\nLuckyCase.isUpperWordCase('UPPER WORD CASE')            // =\u003e true\nLuckyCase.isCapitalWordCase('Capital Word Case')        // =\u003e true\nLuckyCase.isSentenceCase('Sentence case string')        // =\u003e true\nLuckyCase.isMixedCase('mixed_Case')                     // =\u003e true\nLuckyCase.isUpperCase('UPPER50984')                     // =\u003e true\nLuckyCase.isLowerCase('lower_cheese')                   // =\u003e true\nLuckyCase.isCapital('Some')                             // =\u003e true\nLuckyCase.isCapitalized('some')                         // =\u003e false\nLuckyCase.isNotCapital('soMe')                          // =\u003e true\nLuckyCase.isDecapitalized('somE')                       // =\u003e true\nLuckyCase.isValidCaseType('SNAKE_CASE')                 // =\u003e true\nLuckyCase.isValidCaseType('APPLE_CASE')                 // =\u003e false\nLuckyCase.isValidCaseString('validString')              // =\u003e true\nLuckyCase.isValidCaseString('1nV4lid$tring')            // =\u003e false\n```\n\n### Approach 2: Monkey patch the string class\n\nWith monkey patching you can access the same methods (except `deconstantize`, `isValidCaseType`) of LuckyCase directly from strings.\n\nBecause the methods `case` and `cases` are so general and could lead to conflicts, they are called `letterCase` and `letterCases` at strings.\n\n```javascript\n// node js\nconst LuckyCase = require('lucky-case/string');\n// browser\n\u003cscript type=\"text/javascript\" src=\"js/lib/lucky-case.string.min.js\"\u003e\u003c/script\u003e\n\nlet a = 'ExampleString'\n\na.isPascalCase()                        // =\u003e true\na.toSnakeCase()                         // =\u003e 'example_string'\na                                       // =\u003e 'ExampleString'\n\n// identifiers\n// got a other method name here because 'case' might be to common and cause conflicts\nb = 'example'\nb.letterCase()                          // =\u003e 'SNAKE_CASE'\nb.letterCases()                         // =\u003e [ 'SNAKE_CASE', 'CAMEL_CASE', 'DASH_CASE', 'WORD_CASE' ]\n```\n\n\n\n\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\n\n### Option 1: node js yarn\n\nIn your project root directory execute the following command:\n```bash\nyarn add lucky-case\n```\n\n### Option 2: node js npm\n\nIn your project root directory execute the following command:\n```bash\nnpm install lucky-case\n```\n\n### Option 3: Browser\n\nDownload the latest `lucky-case.min.js` or `lucky-case.string.min.js` (string monkey patching version) from the [release page](https://github.com/magynhard/lucky-case/releases) and\nput it in an appropriate folder of your project, e.g. `js/lib`\nand reference it with an script tag in your project:\n```html\n\u003cscript type=\"text/javascript\" src=\"js/lib/lucky-case.min.js\"\u003e\u003c/script\u003e\n```\n\nOptionally you then should add the source file to your build pipeline, if you are using webpack, brunch or any other packager.\n\n  \n\u003ca name=\"documentation\"\u003e\u003c/a\u003e    \n## Documentation\nCheck out the *jsdoc* documentations:\n* [LuckyCase static class version](doc/lucky-case.jsdoc.md)\n* [LuckyCase string monkey patched version](doc/lucky-case-string.jsdoc.md)\n\n\n\n\n\n\u003ca name=\"contributing\"\u003e\u003c/a\u003e    \n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/magynhard/lucky-case. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagynhard%2Flucky-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagynhard%2Flucky-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagynhard%2Flucky-case/lists"}