{"id":20629777,"url":"https://github.com/pb2204/string-methods","last_synced_at":"2025-04-15T18:18:44.404Z","repository":{"id":199240336,"uuid":"702357307","full_name":"PB2204/String-Methods","owner":"PB2204","description":"The String Methods Library is a JavaScript library that provides a collection of useful string manipulation functions.","archived":false,"fork":false,"pushed_at":"2023-10-24T14:24:16.000Z","size":178,"stargazers_count":19,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T18:18:36.180Z","etag":null,"topics":["codescene","collaborate","communityexchange","configcat","digitalocean","ghdesktop","github","github-campus-experts","github-codespaces","github-pages","gitkraken","gitlens","hacktoberfest","hacktoberfest-accepted","jetbrains","learn","microsoft","student-vscode"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/node-string-methods","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/PB2204.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null}},"created_at":"2023-10-09T07:01:45.000Z","updated_at":"2023-10-16T20:28:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"f640fbf5-c8a4-4607-8766-5b44695b1936","html_url":"https://github.com/PB2204/String-Methods","commit_stats":null,"previous_names":["pb2204/string-methods"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PB2204%2FString-Methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PB2204%2FString-Methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PB2204%2FString-Methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PB2204%2FString-Methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PB2204","download_url":"https://codeload.github.com/PB2204/String-Methods/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249125998,"owners_count":21216705,"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":["codescene","collaborate","communityexchange","configcat","digitalocean","ghdesktop","github","github-campus-experts","github-codespaces","github-pages","gitkraken","gitlens","hacktoberfest","hacktoberfest-accepted","jetbrains","learn","microsoft","student-vscode"],"created_at":"2024-11-16T14:06:01.247Z","updated_at":"2025-04-15T18:18:44.384Z","avatar_url":"https://github.com/PB2204.png","language":"JavaScript","readme":"# String Methods Library\n\nA JavaScript library for emulating Python's string methods.\n\n## Table of Contents\n- [Project Description](#project-description)\n- [Motivation](#motivation)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [License](#license)\n- [Code of Conduct](#code-of-conduct)\n- [Learn More](#learn-more)\n- [Contributing](#contributing)\n- [Contact](#contact)\n- [Happy Coding!](#happy-coding)\n\n## Project Description\nThe String Methods Library is a JavaScript library that provides a collection of useful string manipulation functions. It is designed to simplify common string operations and make your coding tasks more efficient.\n\n## Motivation\nThe motivation behind this project is to create a versatile and easy-to-use library for string manipulation in JavaScript. By providing a range of string methods, this library aims to save developers time and effort when working with strings.\n\n## Installation\nYou can install the library using npm:\n\n```bash\nnpm install node-string-methods\n```\n\n## Usage\nTo use the library, import the desired modules in your JavaScript code. Here are some examples of the available modules:\n### Module 1: capitalize\n\n**Description:** Capitalizes the first letter of a string.\n\n**Usage:**\n\n```javascript\nconst { capitalize } = require('node-string-methods');\n\nconst str = 'hello, world!';\nconst capitalized = capitalize(str);\nconsole.log(capitalized); // Output: 'Hello, world!'\n```\n\n### Module 2: caseFold\n\n**Description:** Converts a string to its case-folded form (Unicode normalization).\n\n**Usage:**\n\n```javascript\nconst { caseFold } = require('node-string-methods');\n\nconst str = 'lEtS CaSeFoLd';\nconst caseFolded = caseFold(str);\nconsole.log(caseFolded); // Output: 'lets casefold'\n```\n\n### Module 3: center\n\n**Description:** Centers a string within a specified width, padding with a character.\n\n**Usage:**\n\n```javascript\nconst { center } = require('node-string-methods');\n\nconst str = 'centered';\nconst centeredStr = center(str, 12, '-');\nconsole.log(centeredStr); // Output: '--centered--'\n```\n\n### Module 4: count\n\n**Description:** Counts the occurrences of a substring in a string.\n\n**Usage:**\n\n```javascript\nconst { count } = require('node-string-methods');\n\nconst str = 'hello, hello, world!';\nconst substring = 'hello';\nconst occurrences = count(str, substring);\nconsole.log(occurrences); // Output: 2\n```\n\n### Module 5: encode\n\n**Description:** Encodes special characters in a string for HTML.\n\n**Usage:**\n\n```javascript\nconst { encode } = require('node-string-methods');\n\nconst str = '\u003cdiv\u003eHello, world!\u003c/div\u003e';\nconst encodedStr = encode(str);\nconsole.log(encodedStr); // Output: '\u0026lt;div\u0026gt;Hello, world!\u0026lt;/div\u0026gt;'\n```\n\n### Module 6: endsWith\n\n**Description:** Checks if a string ends with a specified suffix.\n\n**Usage:**\n\n```javascript\nconst { endsWith } = require('node-string-methods');\n\nconst str = 'Hello, world!';\nconst suffix = 'world!';\nconst result = endsWith(str, suffix);\nconsole.log(result); // Output: true\n```\n\n### Module 7: expandTabs\n\n**Description:** Expands tabs in a string to spaces with a specified tab width.\n\n**Usage:**\n\n```javascript\nconst { expandTabs } = require('node-string-methods');\n\nconst str = 'Hello\\tworld!\\t\\tThis is a test.';\nconst tabWidth = 4;\nconst expandedStr = expandTabs(str, tabWidth);\nconsole.log(expandedStr);\n/* Output:\nHello   world!      This is a test.\n*/\n```\n\n### Module 8: find\n\n**Description:** Finds the first occurrence of a substring in a string and returns its index.\n\n**Usage:**\n\n```javascript\nconst { find } = require('node-string-methods');\n\nconst str = 'Hello, world!';\nconst substring = 'world';\nconst index = find(str, substring);\nconsole.log(index); // Output: 7\n```\n\n### Module 9: format\n\n**Description:** Formats a string by replacing placeholders with values.\n\n**Usage:**\n\n```javascript\nconst { format } = require('node-string-methods');\n\nconst template = 'Hello, {name}! You are {age} years old.';\nconst data = { name: 'John', age: 30 };\nconst formattedStr = format(template, data);\nconsole.log(formattedStr); // Output: 'Hello, John! You are 30 years old.'\n```\n\n### Module 10: isAlnum\n\n**Description:** Checks if a string contains only alphanumeric characters.\n\n**Usage:**\n\n```javascript\nconst { isAlnum } = require('node-string-methods');\n\nconst str = 'Hello123';\nconst result = isAlnum(str);\nconsole.log(result); // Output: true\n```\n\n### Module 11: isAlpha\n\n**Description:** Checks if a string contains only alphabetic characters.\n\n**Usage:**\n\n```javascript\nconst { isAlpha } = require('node-string-methods');\n\nconst str = 'Hello';\nconst result = isAlpha(str);\nconsole.log(result); // Output: true\n```\n\n### Module 12: isAscii\n\n**Description:** Checks if a string contains only ASCII characters.\n\n**Usage:**\n\n```javascript\nconst { isAscii } = require('node-string-methods');\n\nconst str = 'Hello, world!';\nconst result = isAscii(str);\nconsole.log(result); // Output: true\n```\n\n### Module 13: isDecimal\n\n**Description:** Checks if a string represents a decimal number.\n\n**Usage:**\n\n```javascript\nconst { isDecimal } = require('node-string-methods');\n\nconst str = '42.123';\nconst result = isDecimal(str);\nconsole.log(result); // Output: true\n```\n\n### Module 14: isDigit\n\n**Description:** Checks if a string contains only digit characters.\n\n**Usage:**\n\n```javascript\nconst { isDigit } = require('node-string-methods');\n\nconst str = '12345';\nconst result = isDigit(str);\nconsole.log(result); // Output: true\n```\n\n### Module 15: isIdentifier\n\n**Description:** Checks if a string is a valid identifier.\n\n**Usage:**\n\n```javascript\nconst { isIdentifier } = require('node-string-methods');\n\nconst identifier = 'myVariable123';\nconst result = isIdentifier(identifier);\nconsole.log(result); // Output: true\n```\n\n### Module 16: isLower\n\n**Description:** Checks if a string contains only lowercase alphabetic characters.\n\n**Usage:**\n\n```javascript\nconst { isLower } = require('node-string-methods');\n\nconst str = 'hello';\nconst result = isLower(str);\nconsole.log(result); // Output: true\n```\n\n### Module 17: isNumeric\n\n**Description:** Checks if a string contains only numeric characters.\n\n**Usage:**\n\n```javascript\nconst { isNumeric } = require('node-string-methods');\n\nconst str = '12345';\nconst result = isNumeric(str);\nconsole.log(result); // Output: true\n```\n\n### Module 18: isSpace\n\n**Description:** Checks if a string contains only whitespace characters.\n\n**Usage:**\n\n```javascript\nconst { isSpace } = require('node-string-methods');\n\nconst str = '    \\t  ';\nconst result = isSpace(str);\nconsole.log(result); // Output: true\n```\n\n### Module 19: isTitle\n\n**Description:** Checks if a string is in title case.\n\n**Usage:**\n\n```javascript\nconst { isTitle } = require('node-string-methods');\n\nconst str = 'This Is Title Case';\nconst result = isTitle(str);\nconsole.log(result); // Output: true\n```\n\n### Module 20: isUpper\n\n**Description:** Checks if a string contains only uppercase alphabetic characters.\n\n**Usage:**\n\n```javascript\nconst { isUpper } = require('node-string-methods');\n\nconst str = 'HELLO';\nconst result = isUpper(str);\nconsole.log(result); // Output: true\n```\n\n### Module 21: join\n\n**Description:** Joins an array of strings into a single string with a specified separator.\n\n**Usage:**\n\n```javascript\nconst { join } = require('node-string-methods');\n\nconst arr = ['apple', 'banana', 'cherry'];\nconst separator = ', ';\nconst result = join(arr, separator);\nconsole.log(result); // Output: 'apple, banana, cherry'\n```\n\n### Module 22: leftJustify\n\n**Description:** Left-justifies a string within a specified width, padding with a character.\n\n**Usage:**\n\n```javascript\nconst { leftJustify } = require('node-string-methods');\n\nconst str = 'left';\nconst width = 10;\nconst paddingChar = '-';\nconst result = leftJustify(str, width, paddingChar);\nconsole.log(result); // Output: 'le'\n```\n\n### Module 23: lower\n\n**Description:** Converts a string to lowercase.\n\n**Usage:**\n\n```javascript\nconst { lower } = require('node-string-methods');\n\nconst str = 'Hello, World!';\nconst result = lower(str);\nconsole.log(result); // Output: 'hello, world!'\n```\n\n### Module 24: leftStrip\n\n**Description:** Removes leading whitespace characters from a string.\n\n**Usage:**\n\n```javascript\nconst { leftStrip } = require('node-string-methods');\n\nconst str = '   Hello, World!';\nconst result = leftStrip(str);\nconsole.log(result); // Output: 'Hello, World!'\n```\n\n### Module 25: makeTrans\n\n**Description:** Translates characters in a string based on a translation table.\n\n**Usage:**\n\n```javascript\nconst { makeTrans } = require('node-string-methods');\n\nconst str = 'Hello, World!';\nconst translationTable = { 'H': 'h', 'W': 'w' };\nconst result = makeTrans(str, translationTable);\nconsole.log(result); // Output: 'hello, world!'\n```\n\n### Module 26: partition\n\n**Description:** Splits a string into three parts based on a separator.\n\n**Usage:**\n\n```javascript\nconst { partition } = require('node-string-methods');\n\nconst str = 'apple,banana,cherry';\nconst separator = ',';\nconst result = partition(str, separator);\nconsole.log(result); // Output: ['apple', ',', 'banana,cherry']\n```\n\n### Module 27: replace\n\n**Description:** Replaces all occurrences of a substring in a string.\n\n**Usage:**\n\n```javascript\nconst { replace } = require('node-string-methods');\n\nconst str = 'Hello, World!';\nconst substring = 'World';\nconst replacement = 'Universe';\nconst result = replace(str, substring, replacement);\nconsole.log(result); // Output: 'Hello, Universe!'\n```\n\n### Module 28: rightFind\n\n**Description:** Finds the last occurrence of a substring in a string.\n\n**Usage:**\n\n```javascript\nconst { rightFind } = require('node-string-methods');\n\nconst str = 'apple, banana, cherry, apple';\nconst substring = 'apple';\nconst result = rightFind(str, substring);\nconsole.log(result); // Output: 21\n```\n\n### Module 29: rightIndex\n\n**Description:** Returns the index of the last occurrence of a substring in a string.\n\n**Usage:**\n\n```javascript\nconst { rightIndex } = require('node-string-methods');\n\nconst str = 'apple, banana, cherry, apple';\nconst substring = 'apple';\nconst result = rightIndex(str, substring);\nconsole.log(result); // Output: 21\n```\n\n### Module 30: rightJustify\n\n**Description:** Right-justifies a string within a specified width, padding with a character.\n\n**Usage:**\n\n```javascript\nconst { rightJustify } = require('node-string-methods');\n\nconst str = 'right';\nconst width = 10;\nconst paddingChar = '-';\nconst result = rightJustify(str, width, paddingChar);\nconsole.log(result); // Output:--right'\n```\n\n### Module 31: rightPartition\n\n**Description:** Splits a string into three parts based on a separator from the right.\n\n**Usage:**\n\n```javascript\nconst { rightPartition } = require('node-string-methods');\n\nconst str = 'apple,banana,cherry';\nconst separator = ',';\nconst result = rightPartition(str, separator);\nconsole.log(result); // Output: ['apple,banana', ',', 'cherry']\n```\n\n### Module 32: rightStrip\n\n**Description:** Removes trailing whitespace characters from a string.\n\n**Usage:**\n\n```javascript\nconst { rightStrip } = require('node-string-methods');\n\nconst str = 'Hello, World!   ';\nconst result = rightStrip(str);\nconsole.log(result); // Output: 'Hello, World!'\n```\n\n### Module 33: split\n\n**Description:** Splits a string into an array of substrings based on a separator.\n\n**Usage:**\n\n```javascript\nconst { split } = require('node-string-methods');\n\nconst str = 'apple,banana,cherry';\nconst separator = ',';\nconst result = split(str, separator);\nconsole.log(result); // Output: ['apple', 'banana', 'cherry']\n```\n\n### Module 34: splitLines\n\n**Description:** Splits a multi-line string into an array of lines.\n\n**Usage:**\n\n```javascript\nconst { splitLines } = require('node-string-methods');\n\nconst str = 'Line 1\\nLine 2\\nLine 3';\nconst result = splitLines(str);\nconsole.log(result); // Output: ['Line 1', 'Line 2', 'Line 3']\n```\n\n### Module 35: startsWith\n\n**Description:** Checks if a string starts with a specified prefix.\n\n**Usage:**\n\n```javascript\nconst { startsWith } = require('node-string-methods');\n\nconst str = 'Hello, World!';\nconst prefix = 'Hello';\nconst result = startsWith(str, prefix);\nconsole.log(result); // Output: true\n```\n\n### Module 36: strip\n\n**Description:** Removes leading and trailing whitespace characters from a string.\n\n**Usage:**\n\n```javascript\nconst { strip } = require('node-string-methods');\n\nconst str = '   Hello, World!   ';\nconst result = strip(str);\nconsole.log(result); // Output: 'Hello, World!'\n```\n\n### Module 37: swapCase\n\n**Description:** Swaps the case (upper to lower and vice versa) of characters in a string.\n\n**Usage:**\n\n```javascript\nconst { swapCase } = require('node-string-methods');\n\nconst str = 'Hello, World!';\nconst result = swapCase(str);\nconsole.log(result); // Output: 'hELLO, wORLD!'\n```\n\n### Module 38: title\n\n**Description:** Converts a string to title case (capitalizes the first letter of each word).\n\n**Usage:**\n\n```javascript\nconst { title } = require('node-string-methods');\n\nconst str = 'hello world';\nconst result = title(str);\nconsole.log(result); // Output: 'Hello World'\n```\n\n### Module 39: upper\n\n**Description:** Converts a string to uppercase.\n\n**Usage:**\n\n```javascript\nconst { upper } = require('node-string-methods');\n\nconst str = 'Hello, World!';\nconst result = upper(str);\nconsole.log(result); // Output: 'HELLO, WORLD!'\n```\n\n### Module 40: zeroFill\n**Description**: Pads a number with leading zeros to a specified width.\n\n**Usage**:\n\n```javascript\nconst { zeroFill } = require('node-string-methods');\n\nconst num = 42;\nconst width = 5;\nconst result = zeroFill(num, width);\nconsole.log(result); // Output: '00042'\n```\n## Examples\nFor more examples and detailed documentation, please refer to the [docs](./string-methods/docs/) directory.\n\n## License\nThis project is licensed under the [MIT License](LICENSE).\n\n## Code of Conduct\nPlease read our [Code of Conduct](CODE_OF_CONDUCT.md) to understand the behavior expected in our community.\n\n## Learn More\nExplore our [Learn.md](Learn.md) file to find additional resources for learning and improving your skills.\n\n## Contributing\nWe welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for more details on how to get started.\n\n## Contact\nFor any questions or feedback, feel free to contact me:\n- Name: [Pabitra Banerjee](https://pabitrabanerjee.me)\n- Email: [Pabitra Banerjee](mailto:rockstarpabitra2204@gmail.com)\n- GitHub: [PB2204](https://github.com/pb2204)\n\n## Happy Coding 🚀\nWe hope you find the String Methods Library useful in your projects. Happy coding!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpb2204%2Fstring-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpb2204%2Fstring-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpb2204%2Fstring-methods/lists"}