├── .circleci └── config.yml ├── .codecov.yml ├── .commitlintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md └── stale.yml ├── .gitignore ├── .package-template ├── README.md ├── package.json ├── src │ └── index.js └── test │ └── index.js ├── .prettierrc ├── CODE-OF-CONDUCT.md ├── LICENCE ├── README.md ├── assets └── logo.svg ├── babel.config.js ├── docs └── pages │ └── api.md ├── lerna.json ├── package.json ├── packages ├── cache │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── compare │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── compose │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── count │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── countWords │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── distance │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── endsWith │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── ends-with.test.js ├── escapeHTML │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── head │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── includes │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── includes.test.js ├── insert │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── insert.test.js ├── isAlpha │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── isAlphaNumeric │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── isEmpty │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── isLowerCase │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── isNumeric │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── isNumeric.test.js ├── isString │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── isUpperCase │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── plexis │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ ├── __snapshots__ │ │ └── index.js.snap │ │ └── index.js ├── repeat │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── startsWith │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── tail │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toCamelCase │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toCapitals │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toChicago │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toChunks │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toEllipsis │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toHuman │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toLower │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toPascalCase │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toPlural │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toPred │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toSnakeCase │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toSucc │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toSwap │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── toSwapCase │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── swap-case.test.js ├── toTitle │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── when │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── withoutDiacritics │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js ├── withoutHTML │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js └── withoutIndent │ ├── README.md │ ├── package.json │ ├── src │ └── index.js │ └── test │ └── index.js └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | codecov: codecov/codecov@1.0.5 5 | 6 | defaults: &defaults 7 | working_directory: ~/repo 8 | docker: 9 | - image: circleci/node:lts 10 | 11 | jobs: 12 | test: 13 | <<: *defaults 14 | steps: 15 | - checkout 16 | - restore_cache: 17 | keys: 18 | - v1-dependencies-{{ checksum "package.json" }} 19 | - v1-dependencies- 20 | 21 | - run: yarn install 22 | - run: 23 | name: Bootstrap lerna 24 | command: yarn bootstrap 25 | 26 | - run: 27 | name: Run tests and collect coverage report 28 | command: yarn cover 29 | 30 | - codecov/upload: 31 | file: coverage/lcov.info 32 | 33 | - save_cache: 34 | paths: 35 | - node_modules 36 | key: v1-dependencies-{{ checksum "package.json" }} 37 | 38 | - persist_to_workspace: 39 | root: ~/repo 40 | paths: . 41 | 42 | deploy: 43 | <<: *defaults 44 | steps: 45 | - attach_workspace: 46 | at: ~/repo 47 | - run: 48 | name: Set registry URL 49 | command: npm set registry https://packagecloud.io/armando/node-test-package/npm/ 50 | - run: 51 | name: Authenticate with registry 52 | command: echo "//packagecloud.io/armando/node-test-package/npm/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc 53 | - run: 54 | name: Publish package 55 | command: yarn run publish 56 | 57 | workflows: 58 | version: 2 59 | test-deploy: 60 | jobs: 61 | - test 62 | - deploy: 63 | requires: 64 | - test 65 | filters: 66 | tags: 67 | only: /^v.*/ 68 | branches: 69 | ignore: /.*/ 70 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: yes 3 | comment: 4 | layout: 'header, reach,diff,flags,tree' 5 | behavior: default 6 | require_changes: false # if true: only post the comment if coverage changes 7 | branches: null 8 | flags: null 9 | paths: null 10 | -------------------------------------------------------------------------------- /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = {extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes']}; 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve plexis 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. Even a usecase can help us. 11 | 12 | **To Reproduce** 13 | Steps to reproduce the behavior (include versions of relevant packages): 14 | 15 | Maybe using codesandbox or JSFiddle in order to recreate the bug ? 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Additional context** 21 | Add any other context about the problem here. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement, 6 | assignees: '' 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. You may also suggest some test cases, naming conventions, suggestions etc. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question for the community 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | --- 8 | 9 | Don't be afraid to ask anything! 10 | There's no such thing as a stupid question. 11 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 10 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | - enhancement 10 | 11 | # Label to use when marking an issue as stale 12 | staleLabel: wontfix 13 | 14 | # Comment to post when marking an issue as stale. Set to `false` to disable 15 | markComment: > 16 | This issue has been automatically marked as stale because it has not had 17 | recent activity. It will be closed if no further activity occurs. Thank you 18 | for your contributions. May the force be with you! 19 | 20 | # Comment to post when closing a stale issue. Set to `false` to disable 21 | closeComment: false 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .nyc_output 2 | *.log 3 | .prettierrc 4 | .circleci 5 | *.lock 6 | dist 7 | node_modules 8 | coverage 9 | package-lock.json 10 | -------------------------------------------------------------------------------- /.package-template/README.md: -------------------------------------------------------------------------------- 1 | ## `nameOfTheModule` 2 | 3 | A proper description 4 | 5 | `npm i @plexis/name-of-the-module` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import toTitle from '@plexis/to-name-of-the-module'; 11 | 12 | nameOfTheModule('param 1'); // returns 'Put the output here' 13 | nameOfTheModule('param 1', 'param 2'); // returns 'Put the output here' 14 | ``` 15 | 16 | **Aliases** 17 | 18 | ```javascript 19 | import {nameOfTheModule} from 'plexis'; 20 | import {anotherExport} from 'plexis'; 21 | ``` 22 | -------------------------------------------------------------------------------- /.package-template/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/this-is-a-template-package", 3 | "version": "ADD YOUR VERSION NUMBER", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": ["dist", "src"], 8 | "license": "MIT", 9 | "keywords": [ 10 | "utility", 11 | "string", 12 | "parse", 13 | "format", 14 | "validate" 15 | ], 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/plexis-js/plexis.git" 19 | }, 20 | "publishConfig": { 21 | "access": "public" 22 | } 23 | } -------------------------------------------------------------------------------- /.package-template/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description This is a sample description 3 | * @param {String} text 4 | * @example 5 | * toPred('b') // returns 'a' 6 | * toPred('B') // returns 'A' 7 | * toPred('BCD') // returns 'ABC' 8 | */ 9 | const toPred = text => 10 | text 11 | .split('') 12 | .map(s => String.fromCharCode(s.charCodeAt(0) - 1)) 13 | .join(''); 14 | 15 | export default toPred; 16 | -------------------------------------------------------------------------------- /.package-template/test/index.js: -------------------------------------------------------------------------------- 1 | it('this is a test', () => { 2 | expect(1).toBe(1); 3 | }); 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "singleQuote": true, 4 | "bracketSpacing": false 5 | } -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Theodore Vorillas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | [![Plexis](./assets/logo.svg)](https://github.com/plexis-js/plexis) 4 | 5 | ### Lo-fi, powerful, community-driven string manipulation library. 6 | 7 |
8 | 9 | This is the main monorepo codebase of Plexis.js a production-ready string manipulation library that's community-driven. 10 | 11 | [![npm version](https://badge.fury.io/js/plexis.svg)](https://www.npmjs.com/package/plexis) 12 | [![bundle size](https://badgen.net/bundlephobia/minzip/plexis)](https://bundlephobia.com/result?p=plexis) 13 | [![CircleCI](https://circleci.com/gh/plexis-js/plexis/tree/master.svg?style=shield)](https://circleci.com/gh/plexis-js/plexis/tree/master) 14 | [![Codecov](https://codecov.io/gh/plexis-js/plexis/branch/master/graph/badge.svg)](https://codecov.io/gh/plexis-js/plexis/branch/master) 15 | 16 | ## What is Plexis? 17 | 18 | ### Vision 19 | 20 | For the past few years managing, contributing or even starting an open-source project could be hard, especially for newcomers. Plexis was born and driven by the JavaScript community. Our initial goal is to provide a production-ready set of utilities and help people understand how an open-source project is maintained. Plexis is driven by our contributors and it should always stay that way. 21 | 22 | You may have noticed that some functions are missing and there are [lots of open issues](https://github.com/plexis-js/plexis/issues) in our repo. That's because we want to allow people to create through the process of learning. Plexis grows with the community and we want to provide a friendly environment for people to get creative, have fun and expand their expertise into JavaScript. 23 | 24 | **Plexis aims to be the best and most flexible library for string operations in the JavaScript and also encourage everyone to learn.** 25 | 26 | Do you want to get your hands dirty? Learn more about [contributing](#contributing). 27 | 28 | ### Docs 29 | 30 | - [Installing](#installing) 31 | - [Using Plexis](#using) 32 | - [API](/docs/pages/api.md) 33 | - [Ground rules](#ground-rules) 34 | - [What you will learn by contributing](#what-you-will-learn-by-contributing) 35 | - [Codebase and technologies](#codebase-and-technologies) 36 | - [Contributing](#contributing) 37 | - [Great, how do I get started?](#great-how-do-i-get-started) 38 | - [How to contribute](#how-to-contribute) 39 | - [Creating a new issue](#creating-a-new-issue) 40 | - [Setup your environment](#setup-your-environment) 41 | - [Pick an open issue](#pick-an-open-issue) 42 | - [Writing code for Plexis](#writing-code-for-plexis) 43 | - [Naming conventions](#naming-conventions) 44 | - [Creating a new package](#creating-a-new-package) 45 | - [Pull requests](#pull-requests) 46 | - [Common issues and pitfalls](#common-issues-and-pitfalls) 47 | - [Learning resources](#learning-resources) 48 | 49 | ## Installing 50 | 51 | You may install Plexis by the registry using: `npm install --save plexis`. Plexis is a mosaic of tiny utility functions, each one lives within its own package inside the monorepo. Thus you may use just a tiny slice of Plexis by installing individual packages: 52 | 53 | ```bash 54 | npm install @plexis/without-diacritics @plexis/toPred 55 | ``` 56 | 57 | ## Using 58 | 59 | Plexis utilities can be directly used, Plexis is production-ready and made for Node.js as well as the web. You can directly include and use any module from Plexis inside your project. 60 | 61 | ```javascript 62 | import {toPred} from 'plexis'; 63 | console.log(toPred('A')); // B 64 | ``` 65 | 66 | ## Ground rules 67 | 68 | All conversations code pieces on Plexis agree to our underlying code of conduct. This code of conduct also applies to all conversations that happen within our contributor community here on GitHub. We expect discussions in issues and pull requests to stay positive, productive, and respectful. 69 | 70 | ## What you will learn by contributing 71 | 72 | The basic idea behind Plexis is to help people understand and learn how to use the fundamentals of JavaScript. By contributing you get into: 73 | 74 | - Mastering JavaScript ES6. 75 | - Understanding how functions and closures work. 76 | - Understanding how strings and arrays work in JavaScript. You are gonna find yourself using `Array.prototype.reduce()` or `Array.prototype.map()` like a lot :) 77 | 78 | - Understanding how the NPM registry works, the anatomy of `package.json` and every single part of creating and publishing a package. 79 | 80 | - Working with pull requests, forks, GIT and the whole workflow of an open-source project. 81 | - Learning how unit testing works. 82 | - Taking a look at how a CI/CD workflow works along with the NPM registry. 83 | 84 | ## Codebase and technologies 85 | 86 | Ok, now let's talk about the architecture of this monorepo: 87 | Every single utility function exists as an independent package, everything comes together and gets bundled into a single source of truth, the main Plexis package. 88 | 89 | Also, is a list of all the technologies and services we use: 90 | 91 | - **Lerna**: used for publishing and managing the monorepo packages. 92 | - **Babel**: used as a JavaScript compiler. 93 | - **Jest**: used for testing. 94 | - **Yarn**: used as a package manager. 95 | - **JSDoc**: used as a documentation manager. 96 | - **CircleCi**: used as a CI/CD provider. 97 | - **Commitlint**: used for linting our commit messages. 98 | - **Prettier**: used for code linting and formatting. 99 | 100 | ### Folder structure 101 | 102 | ```sh 103 | plexis/ 104 | ├── .circleci # CI/CD config 105 | ├── .circleci # CI/CD config 106 | ├── .package-template # A sample package template 107 | ├── docs # Our official documentation 108 | └── packages # The heartbeat of plexis 109 | ``` 110 | 111 | ## Contributing 112 | 113 | **We welcome any contributions from the community!** Plexis is made, driven and maintained by the community. We want to offer everyone a fair chance to make their first steps into open-source and learn through the journey. 114 | 115 | ## Great, how do I get started? 116 | 117 | Plexis has a [Code of Conduct](CODE-OF-CONDUCT.md). Please review and help enforce this code of conduct to help us foster an open and inclusive project. 118 | 119 | ### How to Contribute 120 | 121 | First things first, thanks so much! Feel free to contribute by opening and commenting on issues, helping answer questions, updating or improving our documentation, or opening a pull request. For quick bug fixes or PRs that address an open issue, feel free to open a PR. You can suggest API changes or dig through your codebase and make us a gift with that precious function of yours. 122 | 123 | Even the tiniest piece of code, knowledge or even a few minutes you can spare for Plexis are really important for us. 124 | [Code of Conduct](CODE-OF-CONDUCT.md) 125 | 126 | ### Creating a new issue 127 | 128 | We have set up proper GitHub issue templates with guidelines about asking for features, fixing a bug or even questions. We are waiting for your ideas to start flowing. 129 | 130 | ### Setup your environment 131 | 132 | Ok, so you found the perfect issue for getting started. 133 | You can set up your working environment simply by installing `git`, `Node.js`, `npm` and `yarn`. Use your favorite IDE and you are ready to rock and roll. We prefer using VSCode along with a few extras: 134 | 135 | - The _prettier_ extension for code formating 136 | - The _Document this_ extension for JSDoc 137 | - The _Jest_ extension for writing and managing tests. 138 | 139 | Now you can locally clone the project as: `git clone git@github.com:plexis-js/plexis.git`. Use yarn to install any missing dependencies simply by typing `yarn` in your CLI. 140 | 141 | ### Pick an open issue 142 | 143 | Plexis is all about teaching people. You can found lots of open issues with different types of difficulty. Usually, there are labels that they can help you find the best open issue for you. Find the best issue for you and let's get started. 144 | 145 | Usually, you will find yourself creating a new package or as it is said "a feature request", thus we are trying to provide as much information, test cases or examples as possible. 146 | 147 | ### Writing code for Plexis 148 | 149 | Plexis is using ES6 syntax at full speed. Plexis also uses the monorepo architecture. Every utility function is also a single entry package under the `@plexis` organization. 150 | Some prior knowledge of string operations, regular expressions or array operations are nice to have but certainly not required, we will learn and grow together. 151 | 152 | ### Naming conventions 153 | 154 | Each utility is named using the camelCase convention. Since our utilities are used for string operations you will spot a pattern of missing verbs upon naming our methods. 155 | 156 | For example, a utility function that converts a string to camelCase can be named as `toCamelCase`, which references to `text => transformToCamelCase => output`. For convenience reasons the main Plexis packages also exports a few aliases like `dasherize` or `titleize`. 157 | 158 | ### Creating a new package 159 | 160 | If you want to create a new package we are on a great path 🎉. 161 | You need to take a few additional steps. Let's assume that you need to create a new package for the `camelCase` utility. 162 | 163 | First thing first we need to create a new `@plexis` packages using `lerna create @plexis/came-case`. \_Note: NPM does not allows uppercase characters for packages`. 164 | 165 | You can use `lerna create` for creating a new package, more info can be found [here](https://github.com/lerna/lerna/tree/master/commands/create). You should include all the available information for the new package like `name`, `version`, Alternatively, we are providing [a template for new packages](/..package-template). Keep in mind that the name of package folders should be in camelCase and package.json details should be aligned with the other packages and `lerna.json`. For packages with dependencies to other `@plexis` packages, you can use `yarn bootstrap` which under the hood uses `lerna bootstrap`, learn more about bootstrapping [here](https://github.com/lerna/lerna/tree/master/commands/bootstrap). 166 | 167 | Afterward, create an `src` and a `test` folder, place your files and write the appropriate test cases for unit testing. 168 | 169 | _Note: Usually each package is a single function, thus the coverage limit is super easy to reach out, still, sometimes, we need to cover a lot of different cases due to feature's requirements._ 170 | 171 | A sample folder for `camelCase` would look like this: 172 | 173 | ```sh 174 | packages/ 175 | ├── ... 176 | ├── ... 177 | └── toCamelCase/ 178 | ├── src/ 179 | ├── test/ 180 | └── package.json 181 | ``` 182 | 183 | Finally, you should create a JSDoc comment block for your package, providing a proper description, some code examples and documenting the parameters passed through the function. You shall also create or update the `README.md` or any related documentation files. 184 | 185 | Last but not least you shall update the main `plexis` package with exports all the submodules. Since the main `plexis` module uses snapshots for testing, you need to run `yarn test -u` to update the snapshot testing. 186 | 187 | :bulb: Tip: If your pull request resolves an open issue, don't forget to use [GitHub keywords](https://help.github.com/en/github/managing-your-work-on-github/closing-issues-using-keywords) in the description of your commit message, e.g., **closes #1**, to automatically close the equivalent issue upon merge. 188 | 189 | ### Pull requests 190 | 191 | In a nutshell, to submit a pull request, follow these steps: 192 | 193 | 1. Fork and clone this repo, 194 | 2. Create a branch for your changes. 195 | 3. Install dependencies with `yarn`. 196 | 4. Ensure tests are passing by running `yarn test`. Update any snapshots using `yarn test -u`. 197 | 5. Update the docs or `README.md` file if required. 198 | 6. If you're fixing a bug, it's recommended to write a failing test before writing any code. 199 | 7. Make changes locally and commit them. 200 | 8. Try to make sure tests still pass and that there's a great coverage and clear test cases. 201 | 9. Push your branch to origin. 202 | 10. Open a pull request in this repository with a clear title and description and link to any relevant issues 203 | 11. Wait for a maintainer to review your pull request. 204 | 205 | :bulb: Tip: `yarn test` failing for `packages/plexis/test/index.js`? Try running `yarn bootstrap` before running `yarn test` again. 206 | 207 | ### Common issues and pitfalls 208 | 209 | - Lerna is a powerful tool, try to get through the documentation, make yourself familiar with the commands and follow the appropriate steps as described above. 210 | - Yarn can be a lifesaver for dependency management, try to avoid mixing `npm` and `yarn`. 211 | - Commitlint can be frustrating. Please use it all consciously as it provides a consistent `git` history. 212 | 213 | - If you don't know how to do something, just ask for help. We got your back! 214 | 215 | ### Learning resources 216 | 217 | Here are some learning resources, free tutorials, and books: 218 | 219 | #### ES6 220 | 221 | - https://www.tutorialspoint.com/es6/index.htm 222 | - https://2ality.com/ 223 | - https://exploringjs.com/ 224 | 225 | #### Jest 226 | 227 | - https://www.youtube.com/watch?v=7r4xVDI2vho 228 | - https://blog.logrocket.com/testing-with-jest-from-zero-to-hero-85ce0e9cc953/ 229 | 230 | #### Lerna 231 | 232 | - https://github.com/reggi/lerna-tutorial 233 | - https://www.youtube.com/watch?v=p6qoJ4apCjA 234 | - https://codeburst.io/monorepos-by-example-part-1-3a883b49047e 235 | -------------------------------------------------------------------------------- /assets/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [['@babel/env', {loose: true}]], 3 | env: { 4 | esm: { 5 | presets: [['@babel/env', {loose: true, modules: false}]] 6 | } 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /docs/pages/api.md: -------------------------------------------------------------------------------- 1 | ## API 2 | 3 | - [cache](/packages/cache) 4 | - [compare](/packages/compare) 5 | - [compose](/packages/compose) 6 | - [countWords](/packages/countWords) 7 | - [distance](/packages/distance) 8 | - [endsWith](/packages/endsWith) 9 | - [escapeHTML](/packages/escapeHTML) 10 | - [head](/packages/head) 11 | - [insert](/packages/insert) 12 | - [isAlpha](/packages/isAlpha) 13 | - [isAlphaNumeric](/packages/isAlphaNumeric) 14 | - [isEmpty](/packages/isEmpty) 15 | - [isLowerCase](/packages/isLowerCase) 16 | - [isNumeric](/packages/isNumeric) 17 | - [includes](/packages/includes) 18 | - [isString](/packages/isString) 19 | - [isUpperCase](/packages/isUpperCase) 20 | - [repeat](/packages/repeat) 21 | - [startsWith](/packages/startsWith) 22 | - [toCamelCase](/packages/toCamelCase) 23 | - [toCapitals](/packages/toCapitals) 24 | - [toChicago](/packages/toChicago) 25 | - [toChunks](/packages/toChunks) 26 | - [toHuman](/packages/toHuman) 27 | - [toLower](/packages/toLower) 28 | - [toPascalCase](/packages/toPascalCase) 29 | - [toPlural](/packages/toPlural) 30 | - [toPred](/packages/toPred) 31 | - [toSnakeCase](/packages/toSnakeCase) 32 | - [toSucc](/packages/toSucc) 33 | - [toSwapCase](/packages/toSwapCase) 34 | - [toTitle](/packages/toTitle) 35 | - [when](/packages/when) 36 | - [withoutDiacritics](/packages/withoutDiacritics) 37 | - [withoutHTML](/packages/withoutHTML) 38 | - [withoutIndent](/packages/withoutIndent) 39 | - [tail](/packages/tail) 40 | - [toEllipsis](/packages/toEllipsis) 41 | - [toSwap](/packages/toSwap) 42 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.22", 3 | "npmClient": "yarn", 4 | "packages": [ 5 | "packages/*" 6 | ], 7 | "create": { 8 | "license": "MIT" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "prettier": "prettier \"packages/**/{src,test,examples}/**/*.js\" --write", 5 | "prettier:docs": "prettier \"docs/**/*.{js,md}\" --write", 6 | "clean": "lerna exec -- rm -rf dist", 7 | "build": "yarn build:cjs && yarn build:esm", 8 | "prepare": "yarn build", 9 | "build:cjs": "cross-env NODE_ENV=cjs lerna exec -- babel src -d dist --root-mode upward", 10 | "build:esm": "cross-env NODE_ENV=esm lerna exec -- babel src -o dist/index.esm.js --root-mode upward", 11 | "bootstrap": "lerna bootstrap", 12 | "publish": "yarn clean && yarn build && lerna publish", 13 | "cover": "yarn test --coverage", 14 | "test": "jest" 15 | }, 16 | "devDependencies": { 17 | "@babel/cli": "^7.2.3", 18 | "@babel/core": "^7.4.0", 19 | "@babel/plugin-transform-runtime": "^7.4.0", 20 | "@babel/preset-env": "^7.4.2", 21 | "@babel/register": "^7.4.0", 22 | "@commitlint/cli": "8.2.0", 23 | "@commitlint/config-conventional": "8.2.0", 24 | "@commitlint/config-lerna-scopes": "8.2.0", 25 | "cross-env": "^6.0.3", 26 | "husky": "^3.0.1", 27 | "jest": "^24.8.0", 28 | "lerna": "^3.13.4", 29 | "lint-staged": "^9.2.0", 30 | "prettier": "^1.16.4" 31 | }, 32 | "jest": { 33 | "testMatch": [ 34 | "**/packages/**/test/*.js" 35 | ], 36 | "collectCoverageFrom": [ 37 | "**/packages/**/src/*.js" 38 | ], 39 | "coverageReporters": [ 40 | "lcov", 41 | "text", 42 | "html" 43 | ] 44 | }, 45 | "repository": { 46 | "type": "git", 47 | "url": "git+https://github.com/jxnblk/styled-system.git" 48 | }, 49 | "husky": { 50 | "hooks": { 51 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 52 | "pre-commit": "lint-staged" 53 | } 54 | }, 55 | "lint-staged": { 56 | "*.{js,md}": [ 57 | "prettier --write", 58 | "git add" 59 | ] 60 | } 61 | } -------------------------------------------------------------------------------- /packages/cache/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/cache` 2 | 3 | A caching mechanism for string operations. 4 | 5 | `npm i @plexis/cache` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import cache from '@plexis/cache'; 11 | 12 | const toLower = x => x.toLowerCase(); 13 | const toLowerCache = cache(toLower); 14 | 15 | // We are adding a dummy resolver function which returns the same cache every single time 16 | const toLowerCacheWithResolver = cache(toLower, x => 'a'); 17 | 18 | toLowerCache('A'); // returns a; 19 | toLowerCache('B'); // returns b; 20 | 21 | toLowerCacheWithResolver('A'); // returns a; 22 | toLowerCacheWithResolver('B'); // returns a !!; 23 | ``` 24 | 25 | **Aliases** 26 | 27 | ```javascript 28 | import cache from '@plexis/cache'; 29 | import {cache, memoize} from 'plexis'; 30 | ``` 31 | -------------------------------------------------------------------------------- /packages/cache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/cache", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "license": "MIT", 8 | "description": "A caching mechanism for string operations. ", 9 | "files": [ 10 | "dist", 11 | "src" 12 | ], 13 | "authors": [ 14 | "Theodore Vorillas (https://vorillaz.com)", 15 | "roemhildtg " 16 | ], 17 | "keywords": [ 18 | "utility", 19 | "string", 20 | "parse", 21 | "format", 22 | "validate", 23 | "cache" 24 | ], 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/plexis-js/plexis.git" 28 | }, 29 | "publishConfig": { 30 | "access": "public" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/cache/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Function} [func] The function to have its output memoized. 3 | * @param {Function} [resolver] The function to resolve the caching mechanism. 4 | * @returns {Function} Returns the new memoized function. 5 | */ 6 | const cache = (func, resolver) => { 7 | if (typeof resolver !== 'function') { 8 | resolver = null; 9 | } 10 | const cached = key => { 11 | key = resolver ? resolver.call(this, key) : key; 12 | const _cache = cached.cache; 13 | 14 | if (_cache.has(key)) { 15 | return _cache.get(key); 16 | } 17 | 18 | const result = func.call(this, key); 19 | cached.cache = _cache.set(key, result) || cache; 20 | return result; 21 | }; 22 | 23 | const CacheConstructor = cache.Cache || Map; 24 | cached.cache = new CacheConstructor(); 25 | return cached; 26 | }; 27 | 28 | cache.Cache = Map; 29 | 30 | export default cache; 31 | -------------------------------------------------------------------------------- /packages/cache/test/index.js: -------------------------------------------------------------------------------- 1 | import cache from '../src'; 2 | 3 | const toLower = x => x.toLowerCase(); 4 | 5 | it('works with basics', () => { 6 | const toLowerMock = jest.fn(key => { 7 | return toLower(key); 8 | }); 9 | 10 | const toLowerCache = cache(toLowerMock); 11 | expect(toLowerCache('A')).toEqual('a'); 12 | expect(toLowerCache('A')).toEqual('a'); 13 | expect(toLowerMock.mock.calls.length).toEqual(1); 14 | }); 15 | 16 | it('works with a resolver function', () => { 17 | const toLowerCacheWithResolver = cache(toLower, x => 'a'); 18 | const toLowerCache = cache(toLower); 19 | expect(toLowerCacheWithResolver('A')).toEqual('a'); 20 | expect(toLowerCacheWithResolver('B')).toEqual('a'); 21 | }); 22 | 23 | it('exposes a .cache object', () => { 24 | const toLowerCache = cache(toLower); 25 | toLowerCache('A'); 26 | expect(toLowerCache.cache.get('A')).toEqual('a'); 27 | }); 28 | -------------------------------------------------------------------------------- /packages/compare/README.md: -------------------------------------------------------------------------------- 1 | ## `compare` 2 | 3 | Compares input text as humans do. 4 | 5 | `npm i @plexis/compare` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import naturalCompare from '@plexis/compare'; 11 | 12 | compare('A', 'b'); // returns 1 13 | compare('A woman', 'a woman'); // returns 1 14 | compare('b', 'B'); // returns -1 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import compare from '@plexis/compare'; 21 | import {compare, compareLikeHuman, naturalCompare} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/compare/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/compare", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "author": "Brandon Skinner ", 12 | "license": "MIT", 13 | "keywords": [ 14 | "utility", 15 | "string", 16 | "parse", 17 | "format", 18 | "validate" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/plexis-js/plexis.git" 23 | }, 24 | "publishConfig": { 25 | "access": "public" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/compare/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @description Compares input text as humans do. 3 | * @param {String} first 4 | * @param {String} second 5 | * @returns {Integer} 6 | * @example 7 | * compare('', '') // => 0 8 | * compare('A', 'a') // => 1 9 | * compare('A', 'b') // => 1 10 | * compare('A woman', 'a woman') // => 1 11 | * compare('b', 'B') // => -1 12 | * compare('C', 'b') // => -1 13 | * compare('Qux20', 'Qux5') // => -1 14 | * compare('Qux10', 'Qux11') // => 1 15 | */ 16 | const compare = (first, second) => { 17 | return second.localeCompare(first, undefined, { 18 | numeric: true, 19 | sensitivity: 'case', 20 | caseFirst: 'upper' 21 | }); 22 | }; 23 | 24 | export default compare; 25 | -------------------------------------------------------------------------------- /packages/compare/test/index.js: -------------------------------------------------------------------------------- 1 | import compare from '../src'; 2 | 3 | it('Should compare strings naturally', () => { 4 | expect(compare('', '')).toBe(0); 5 | expect(compare('A', 'a')).toBe(1); 6 | expect(compare('A', 'b')).toBe(1); 7 | expect(compare('A woman', 'a woman')).toBe(1); 8 | expect(compare('b', 'B')).toBe(-1); 9 | expect(compare('C', 'b')).toBe(-1); 10 | expect(compare('Qux20', 'Qux5')).toBe(-1); 11 | expect(compare('Qux10', 'Qux11')).toBe(1); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/compose/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/compose` 2 | 3 | Compose 2 or more functions. 4 | 5 | **Installation** 6 | `npm i @plexis/compose` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import compose from '@plexis/compose'; 12 | const inc = x => x + 1; 13 | const add = (x, y) => x + y; 14 | const ops = compose( 15 | inc, 16 | x => add(x, 2) 17 | ); 18 | 19 | ops(1); // returns 4; 20 | ops(10); // returns 13; 21 | ``` 22 | 23 | **Aliases** 24 | 25 | ```javascript 26 | import compose from '@plexis/compose'; 27 | import {compose, _do} from 'plexis'; 28 | ``` 29 | -------------------------------------------------------------------------------- /packages/compose/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/compose", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Nguyễn Tuấn Dũng " 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "function" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/compose/src/index.js: -------------------------------------------------------------------------------- 1 | const composeTwo = (f, g) => (...x) => 2 | Reflect.apply(f, undefined, [Reflect.apply(g, undefined, x)]); 3 | 4 | /** 5 | * Compose two or more functions 6 | * @param {Function[]} args Array of Function 7 | * @returns {Function} Returns the new composite function. 8 | * @example 9 | * const inc = x => x + 1; 10 | * const add = (x, y) => x + y; 11 | * const ops = compose(inc, x => add(x, 2)); 12 | * 13 | * ops(1); // returns 4; 14 | * ops(10); // returns 13; 15 | */ 16 | const compose = (...args) => args.reduce(composeTwo); 17 | 18 | export default compose; 19 | -------------------------------------------------------------------------------- /packages/compose/test/index.js: -------------------------------------------------------------------------------- 1 | import compose from '../src'; 2 | 3 | const inc = x => x + 1; 4 | const add = (x, y) => x + y; 5 | 6 | it('compose 2 unary functions', () => { 7 | const ops = compose( 8 | inc, 9 | x => add(x, 2) 10 | ); 11 | expect(ops(1)).toBe(4); 12 | expect(ops(10)).toBe(13); 13 | }); 14 | 15 | it('compose unary and binary functions', () => { 16 | const ops = compose( 17 | inc, 18 | add 19 | ); 20 | expect(ops(2, 3)).toBe(6); 21 | expect(ops(-1, 10)).toBe(10); 22 | }); 23 | 24 | it('compose 3 functions', () => { 25 | const ops = compose( 26 | inc, 27 | inc, 28 | x => add(x, 12) 29 | ); 30 | expect(ops(2)).toBe(16); 31 | expect(ops(10)).toBe(24); 32 | }); 33 | -------------------------------------------------------------------------------- /packages/count/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/count` 2 | 3 | Return the number of characters in the input text. 4 | 5 | `npm i @plexis/count` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import count from '@plexis/count'; 11 | 12 | count(); // returns 0 13 | count(''); // returns 0 14 | count('Hello'); // returns 5 15 | count('Hello '); // returns 8 16 | count('Hello ', char => char !== ' '); // returns 5 17 | ``` 18 | 19 | **Aliases** 20 | 21 | ```javascript 22 | import count from '@plexis/count'; 23 | import {count} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/count/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/count", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "description": "Return the number of characters in the input text.", 8 | "keywords": [ 9 | "utility", 10 | "string", 11 | "parse", 12 | "format", 13 | "validate" 14 | ], 15 | "author": "Angel Gonzalez ", 16 | "homepage": "https://github.com/plexis-js/plexis#readme", 17 | "license": "MIT", 18 | "files": [ 19 | "lib" 20 | ], 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git+https://github.com/plexis-js/plexis.git" 27 | }, 28 | "bugs": { 29 | "url": "https://github.com/plexis-js/plexis/issues" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/count/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description This is a sample description 3 | * @param {String} text 4 | * @param (Function) validator, validates if a character should be count or not 5 | * @example 6 | * count('b') // returns 1 7 | * count('Foo') // returns 3 8 | * count('Foo bar') // returns 7 9 | * count('Foo bar ', char => char != ' ') //returns 6 10 | * 11 | */ 12 | const count = (text = '', validator = () => true) => { 13 | let strLen = text ? text.length : 0; 14 | 15 | strLen = 0; 16 | 17 | text.split('').map(letter => { 18 | strLen += validator(letter) ? 1 : 0; 19 | }); 20 | 21 | return strLen; 22 | }; 23 | 24 | export default count; 25 | -------------------------------------------------------------------------------- /packages/count/test/index.js: -------------------------------------------------------------------------------- 1 | import count from '../src'; 2 | 3 | describe('@plexis/count', () => { 4 | it('no first or second parameter given', () => { 5 | expect(count()).toBe(0); 6 | }); 7 | 8 | it('empty string given and no validator for second parameter', () => { 9 | expect(count('')).toBe(0); 10 | }); 11 | 12 | it('no empty string given for first and no validator for second parameter ', () => { 13 | expect(count('Foo bar')).toBe(7); 14 | }); 15 | 16 | it('no empty string given for first and validator for no spaces as second parameter', () => { 17 | expect(count('Foo bar ', char => char !== ' ')).toBe(6); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/countWords/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/count-words` 2 | 3 | Returns the number of words contained in the input text. 4 | 5 | **Installation** 6 | `npm i @plexis/count-words` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import countWords from '@plexis/count-words'; 12 | 13 | countWords(); // returns 0 14 | countWords(''); // returns 0 15 | countWords(' '); // returns 0 16 | countWords('Hello World !!'); // returns 2 17 | ``` 18 | 19 | ## Aliases 20 | 21 | ```javascript 22 | import countWords from '@plexis/count-words'; 23 | import {countWords} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/countWords/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/count-words", 3 | "version": "0.0.22", 4 | "description": "Returns the number of words contained in the input text.", 5 | "keywords": [ 6 | "utility", 7 | "string", 8 | "count" 9 | ], 10 | "author": "protob ", 11 | "homepage": "https://github.com/plexis-js/plexis.git", 12 | "license": "MIT", 13 | "main": "dist/index.js", 14 | "module": "dist/index.esm.js", 15 | "jsnext:main": "./src/index.js", 16 | "files": [ 17 | "dist", 18 | "src" 19 | ], 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/plexis-js/plexis.git" 26 | }, 27 | "bugs": { 28 | "url": "https://github.com/plexis-js/plexis/issues" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/countWords/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Returns the number of words contained in the input text. 3 | * @param {String} string 4 | * @example 5 | * countWords(); // => 0 6 | * countWords(''); // => 0 7 | * countWords(' ') // => 0 8 | * countWords('Hello World') // => 2 9 | * countWords('Hello World !!') // => 2 10 | */ 11 | 12 | const countWords = (string = '') => { 13 | return string 14 | .replace(/[^a-z0-9]+/gi, ',') 15 | .split(',') 16 | .filter(e => String(e).trim()).length; 17 | }; 18 | 19 | export default countWords; 20 | -------------------------------------------------------------------------------- /packages/countWords/test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import countWords from '../src'; 4 | 5 | describe('@plexis/countWords', () => { 6 | it('should retrun 0', () => { 7 | expect(countWords()).toBe(0); 8 | }); 9 | it('should retrun 0', () => { 10 | expect(countWords(' ')).toBe(0); 11 | }); 12 | it('should retrun 2', () => { 13 | expect(countWords('Hello World')).toBe(2); 14 | }); 15 | it('should retrun 2', () => { 16 | expect(countWords('Hello World !!')).toBe(2); 17 | }); 18 | it('should retrun 3', () => { 19 | expect(countWords('Hello Another Dimension !!')).toBe(3); 20 | }); 21 | it('should retrun 3', () => { 22 | expect(countWords('Hello Another Dimension ,.!?;:+-`@#$%^&*()')).toBe(3); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /packages/distance/README.md: -------------------------------------------------------------------------------- 1 | ## `distance` 2 | 3 | Calculates the [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings. 4 | 5 | `npm i @plexis/distance` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import distance from '@plexis/distance'; 11 | distance('book', 'back'); // returns 2 12 | distance('black', 'back'); // returns 1 13 | distance('Foo', 'Bar'); // returns 3 14 | ``` 15 | 16 | **Aliases** 17 | 18 | ```javascript 19 | import distance from '@plexis/distance'; 20 | import {distance, calcLevenshtein, levenshtein} from 'plexis'; 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/distance/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/distance", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "author": "Brandon Skinner ", 12 | "license": "MIT", 13 | "keywords": [ 14 | "utility", 15 | "string", 16 | "parse", 17 | "format", 18 | "validate" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/plexis-js/plexis.git" 23 | }, 24 | "publishConfig": { 25 | "access": "public" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/distance/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Calculates the Levenshtein Distance toStretween two strings 3 | * @param {String} [fromStr] 4 | * @param {String} [toStr] 5 | * @returns {Number} The Levenshtein distance 6 | * @example 7 | * distance('book', 'back') // returns 2 8 | * distance('black', 'back') // returns 1 9 | * distance('Foo', 'Bar') // returns 3 10 | */ 11 | const distance = (fromStr, toStr) => { 12 | if (typeof fromStr !== 'string' || typeof toStr !== 'string') return 0; 13 | if (fromStr.length === 0) return toStr.length; 14 | if (toStr.length === 0) return fromStr.length; 15 | 16 | if (fromStr.length > toStr.length) { 17 | let tmp = fromStr; 18 | fromStr = toStr; 19 | toStr = tmp; 20 | } 21 | 22 | let row = Array(fromStr.length); 23 | let i; 24 | let prev; 25 | let val; 26 | 27 | for (i = 0; i <= fromStr.length; i++) { 28 | row[i] = i; 29 | } 30 | 31 | for (i = 1; i <= toStr.length; i++) { 32 | prev = i; 33 | for (var j = 1; j <= fromStr.length; j++) { 34 | if (toStr[i - 1] === fromStr[j - 1]) { 35 | val = row[j - 1]; 36 | } else { 37 | val = Math.min(row[j - 1] + 1, prev + 1, row[j] + 1); 38 | } 39 | row[j - 1] = prev; 40 | prev = val; 41 | } 42 | row[fromStr.length] = prev; 43 | } 44 | return row[fromStr.length]; 45 | }; 46 | 47 | export default distance; 48 | -------------------------------------------------------------------------------- /packages/distance/test/index.js: -------------------------------------------------------------------------------- 1 | import distance from '../src'; 2 | 3 | it('Should calculate Levenshtein Distance between two strings', () => { 4 | expect(distance('book', 'back')).toBe(2); 5 | expect(distance('black', 'back')).toBe(1); 6 | expect(distance('Foo', 'Bar')).toBe(3); 7 | expect(distance('cool', 'cool')).toBe(0); 8 | expect(distance('There was a black cat', 'There was a black dog')).toBe(3); 9 | expect(distance('!@#$', '!@#$')).toBe(0); 10 | expect(distance('', '', /<([\w]+).*>(.*?)<\/\1>/)).toBe(true); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/tail/README.md: -------------------------------------------------------------------------------- 1 | ## `head` 2 | 3 | Extracts the last length characters from the input text 4 | 5 | `npm i @plexis/tail` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import tail from '@plexis/tail'; 11 | tail(); // => '' 12 | tail('Hello'); // => 'o' 13 | tail('Hello', 2); // => 'lo' 14 | tail('Hello', 100); // => 'Hello' 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import {tail} from 'plexis'; 21 | import {rest} from 'plexis'; 22 | import {last} from 'plexis'; 23 | import {pop} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/tail/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/tail", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/tail/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Extracts the last length characters from the input text 3 | * @param {String} text 4 | * @param {Number} endingPosition, optional 5 | * @example 6 | * tail(); // returns '' 7 | * tail('Hello'); // returns 'o' 8 | * tail('Hello', 2); // returns 'lo' 9 | * tail('Hello', 100); // returns 'Hello' 10 | */ 11 | 12 | const tail = (text, endingPosition = 1) => 13 | text ? text.substring(text.length - endingPosition) : ''; 14 | 15 | export default tail; 16 | -------------------------------------------------------------------------------- /packages/tail/test/index.js: -------------------------------------------------------------------------------- 1 | import tail from '../src'; 2 | 3 | it('Extracts the last length characters from the input text', () => { 4 | expect(tail()).toBe(''); 5 | expect(tail('Hello')).toBe('o'); 6 | expect(tail('Hello', 2)).toBe('lo'); 7 | expect(tail('Hello', 100)).toBe('Hello'); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/toCamelCase/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/toCamelCase` 2 | 3 | Converts the input text to camelCase. 4 | 5 | **Installation** 6 | `npm i @plexis/to-camel-case` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toCamelCase from '@plexis/to-camel-case'; 12 | 13 | toCamelCase('Cool'); //=> 'cool' 14 | toCamelCase('cool mate'); // => 'coolMate' 15 | toCamelCase('Hey how are you today?'); // => 'heyHowAreYouToday' 16 | toCamelCase('PascalCase'); // => 'pascalCase' 17 | toCamelCase('kebab-case'); // => kebabCase 18 | ``` 19 | 20 | **Aliases** 21 | 22 | ```javascript 23 | import {toCamelCase} from 'plexis'; 24 | import {camelCase} from 'plexis'; 25 | import {camelize} from 'plexis'; 26 | ``` 27 | -------------------------------------------------------------------------------- /packages/toCamelCase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-camel-case", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Theodore Vorillas (https://vorillaz.com)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toCamelCase/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string to camel case 3 | * @param {String} text 4 | * @returns {String} camel case text 5 | * @example 6 | * toCamelCase('Cool'); //=> 'cool' 7 | * toCamelCase('cool mate'); // => 'coolMate' 8 | * toCamelCase('Hey how are you today?'); // => 'heyHowAreYouToday' 9 | * toCamelCase('PascalCase'); // => 'pascalCase' 10 | * toCamelCase('kebab-case'); // => kebabCase 11 | */ 12 | 13 | const toCamelCase = string => { 14 | const lowerUpper = (letter, index) => { 15 | return index === 0 ? letter.toLowerCase() : letter.toUpperCase(); 16 | }; 17 | const wordPatt = /^\w|[A-Z]|\b\w/g; 18 | const symbolPatt = /[^a-zA-Z0-9]/g; 19 | let result = string 20 | .trim() 21 | .replace(wordPatt, lowerUpper) 22 | .replace(symbolPatt, ''); 23 | return result; 24 | }; 25 | 26 | export default toCamelCase; 27 | -------------------------------------------------------------------------------- /packages/toCamelCase/test/index.js: -------------------------------------------------------------------------------- 1 | import toCamelCase from '../src'; 2 | 3 | it('converts a given string to camel case', () => { 4 | expect(toCamelCase('Cool')).toBe('cool'); 5 | expect(toCamelCase('cool mate')).toBe('coolMate'); 6 | expect(toCamelCase('Hey how are you today?')).toBe('heyHowAreYouToday'); 7 | expect(toCamelCase('PascalCase')).toBe('pascalCase'); 8 | expect(toCamelCase('kebab-case')).toBe('kebabCase'); 9 | expect(toCamelCase('')).toBe(''); 10 | expect(toCamelCase(' ')).toBe(''); 11 | expect(toCamelCase(' kebab-case PascalCase @hello! ')).toBe('kebabCasePascalCaseHello'); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/toCapitals/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/to-capitals` 2 | 3 | Converts the first character of the input text to upper case. If the second parameter is true, the method converts the rest of the subject to lower case. 4 | 5 | `npm i @plexis/to-capitals` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import toCapitals from '@plexis/to-capitals'; 11 | 12 | toCapitals('foo Bar'); // returns 'Foo Bar' 13 | toCapitals('fOO Bar'); // returns 'FOO Bar' 14 | toCapitals('fOO Bar', true); // returns 'Foo bar' 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import toCapitals from '@plexis/to-capitals'; 21 | import {toCapitals, toFirstCapital, capitalize} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/toCapitals/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-capitals", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "description": "Converts the first character of the input text to upper case. If the second parameter is true, the method converts the rest of the subject to lower case", 8 | "keywords": [ 9 | "utility", 10 | "string" 11 | ], 12 | "author": "Angel Gonzalez ", 13 | "homepage": "https://github.com/plexis-js/plexis#readme", 14 | "license": "MIT", 15 | "files": [ 16 | "lib" 17 | ], 18 | "publishConfig": { 19 | "access": "public" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/plexis-js/plexis.git" 24 | }, 25 | "bugs": { 26 | "url": "https://github.com/plexis-js/plexis/issues" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/toCapitals/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts the first character of the input text to upper case. If the second parameter is true, the method converts the rest of the subject to lower case. 3 | * @param {String} text 4 | * @param {Boolean} isLowercase 5 | * @example 6 | * toPred('foo Bar') // returns 'Foo Bar' 7 | * toPred('fOO Bar') // returns 'FOO Bar' 8 | * toPred('fOO Bar', true) // returns 'Foo bar' 9 | */ 10 | const toCapitals = (text = '', isLowercase = false) => { 11 | let firstCharacter = text.charAt(0).toUpperCase(); 12 | let restOfString = isLowercase ? text.slice(1).toLowerCase() : text.slice(1); 13 | 14 | return firstCharacter + restOfString; 15 | }; 16 | 17 | export default toCapitals; 18 | -------------------------------------------------------------------------------- /packages/toCapitals/test/index.js: -------------------------------------------------------------------------------- 1 | import toCapitals from '../src'; 2 | 3 | describe('@plexis/to-capitals', () => { 4 | it('no params, should be empty string', () => { 5 | expect(toCapitals()).toBe(''); 6 | }); 7 | 8 | it('empty string,, should be empty strin', () => { 9 | expect(toCapitals('')).toBe(''); 10 | }); 11 | 12 | it('should capitalize only first letter, the rest of the string must be intact', () => { 13 | expect(toCapitals('foO bar')).toBe('FoO bar'); 14 | }); 15 | 16 | it('should capitalize only first letter, the rest of the string must be intact', () => { 17 | expect(toCapitals('foO bAr')).toBe('FoO bAr'); 18 | }); 19 | 20 | it('should capitalize the first letter, the rest of the subject to lower case.', () => { 21 | expect(toCapitals('FOO BAR', true)).toBe('Foo bar'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /packages/toChicago/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/to-chicago` 2 | 3 | Convert text into Chicago style 4 | 5 | `npm i @plexis/to-chicago` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import toChicago from '@plexis/to-chicago'; 11 | 12 | toChicago('This is a title'); // returns 'This Is a Title' 13 | toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.' 14 | toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case' 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import toChicago from '@plexis/to-chicago'; 21 | import {toTurabian, toChicagoManualStyle, toChicagoStyle, toChicagoTitle} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/toChicago/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-chicago", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "authors": [ 8 | "Nguyễn Tuấn Dũng " 9 | ], 10 | "files": [ 11 | "dist", 12 | "src" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format" 20 | ], 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/plexis-js/plexis.git" 24 | }, 25 | "publishConfig": { 26 | "access": "public" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/toChicago/src/index.js: -------------------------------------------------------------------------------- 1 | const formatWord = word => 2 | word 3 | .split('-') 4 | .map(s => s.charAt(0).toUpperCase() + s.toLowerCase().substring(1)) 5 | .join('-'); 6 | 7 | // Prepositions list 8 | const wordException = [ 9 | 'a', 10 | 'an', 11 | 'the', 12 | 'and', 13 | 'or', 14 | 'aboard', 15 | 'about', 16 | 'above', 17 | 'across', 18 | 'after', 19 | 'against', 20 | 'along', 21 | 'amid', 22 | 'among', 23 | 'around', 24 | 'as', 25 | 'at', 26 | 'before', 27 | 'behind', 28 | 'below', 29 | 'beneath', 30 | 'beside', 31 | 'between', 32 | 'beyond', 33 | 'but', 34 | 'by', 35 | 'concerning', 36 | 'considering', 37 | 'despite', 38 | 'down', 39 | 'during', 40 | 'except', 41 | 'following', 42 | 'for', 43 | 'from', 44 | 'in', 45 | 'inside', 46 | 'into', 47 | 'like', 48 | 'minus', 49 | 'near', 50 | 'next', 51 | 'of', 52 | 'off', 53 | 'on', 54 | 'onto', 55 | 'opposite', 56 | 'out', 57 | 'outside', 58 | 'over', 59 | 'past', 60 | 'per', 61 | 'plus', 62 | 'regarding', 63 | 'round', 64 | 'save', 65 | 'since', 66 | 'than', 67 | 'through', 68 | 'to', 69 | 'toward', 70 | 'under', 71 | 'underneath', 72 | 'unlike', 73 | 'until', 74 | 'up', 75 | 'upon', 76 | 'versus', 77 | 'via', 78 | 'with', 79 | 'within', 80 | 'without' 81 | ]; 82 | 83 | const formatSentence = sentence => 84 | sentence 85 | .trim() 86 | .split(/\s+/) 87 | .map((word, index) => 88 | index > 0 && wordException.includes(word.toLowerCase()) 89 | ? word.toLowerCase() 90 | : formatWord(word) 91 | ) 92 | .join(' '); 93 | 94 | /** 95 | * @description Convert text into Chicago style 96 | * @param {String} text The text to transform 97 | * @returns {String} Returns text transformed according to the The Chicago Manual of Style. 98 | * @example 99 | * toChicago('This is a title'); // returns 'This Is a Title' 100 | * toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.' 101 | * toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case' 102 | 103 | */ 104 | const toChicago = text => 105 | text 106 | .replace(/\s+/, ' ') 107 | .replace(/\s+([.?!,:;])\s*/, '$1 ') 108 | .concat('.') 109 | .match(/(.*?)([.?!])/g) 110 | .map(sentence => sentence.match(/(.*?)([.?!])/)) 111 | .map(x => formatSentence(x[1]) + x[2]) 112 | .join(' ') 113 | .slice(0, -1) 114 | .trimRight(); 115 | 116 | export default toChicago; 117 | -------------------------------------------------------------------------------- /packages/toChicago/test/index.js: -------------------------------------------------------------------------------- 1 | import toChicago from '../src'; 2 | 3 | it('transform normal string', () => { 4 | expect(toChicago('This is a title')).toBe('This Is a Title'); 5 | }); 6 | 7 | it('transform mixed sentence', () => { 8 | expect(toChicago('in Turabian shows a sample title page for a class paper.')).toBe( 9 | 'In Turabian Shows a Sample Title Page for a Class Paper.' 10 | ); 11 | }); 12 | 13 | it('transform edge case', () => { 14 | expect(toChicago('camelCase PascalCase snake_case and kebab-case')).toBe( 15 | 'Camelcase Pascalcase Snake_case and Kebab-Case' 16 | ); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/toChunks/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/to-chunks` 2 | 3 | Splits the input text into an array of chunks. 4 | 5 | **Installation** 6 | `npm i @plexis/to-chunks` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toChunks from '@plexis/to-chunks'; 12 | 13 | toChunks('Hello world'); 14 | // => ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] 15 | 16 | toChunks(' '); 17 | // => [' ', ' ', ' '] 18 | 19 | toChunks('1234567', 2); 20 | // => ['12', '34', '56', '7'] 21 | 22 | toChunks('1234567', 6); 23 | // => ['123456', '7'] 24 | ``` 25 | 26 | **Aliases** 27 | 28 | ```javascript 29 | import toChunks from '@plexis/to-chunks'; 30 | import {toChunks, chop} from 'plexis'; 31 | ``` 32 | -------------------------------------------------------------------------------- /packages/toChunks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-chunks", 3 | "version": "0.0.22", 4 | "description": "Splits the input text into an array of chunks.", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "jsnext:main": "./src/index.js", 8 | "files": [ 9 | "dist", 10 | "src" 11 | ], 12 | "author": "korczynsk1", 13 | "license": "MIT", 14 | "keywords": [ 15 | "chunks", 16 | "string" 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/plexis-js/plexis.git" 21 | }, 22 | "publishConfig": { 23 | "access": "public" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/toChunks/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string to its equivalent predecessor 3 | * @param {String} text The input String 4 | * @param {Integer} chunkSize The size of each chunk, default to 1 5 | * @example 6 | * toChunks('Hello world'); // => ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] 7 | * toChunks(' '); // => [' ', ' ', ' '] 8 | * toChunks('1234567', 2); // => ['12', '34', '56', '7'] 9 | * toChunks('1234567', 6) // => ['123456', '7'] 10 | */ 11 | const toChunks = (text, chunkSize = 1) => text.match(new RegExp(`.{1,${chunkSize}}`, 'g')); 12 | 13 | export default toChunks; 14 | -------------------------------------------------------------------------------- /packages/toChunks/test/index.js: -------------------------------------------------------------------------------- 1 | import toChunks from '../src'; 2 | 3 | it('create chunks with default chunksize', () => { 4 | expect(toChunks('Hello world')).toStrictEqual([ 5 | 'H', 6 | 'e', 7 | 'l', 8 | 'l', 9 | 'o', 10 | ' ', 11 | 'w', 12 | 'o', 13 | 'r', 14 | 'l', 15 | 'd' 16 | ]); 17 | }); 18 | 19 | it('create chunks of empty strings', () => { 20 | expect(toChunks(' ')).toStrictEqual([' ', ' ', ' ']); 21 | }); 22 | 23 | it('create chunks for chunk size equal 2', () => { 24 | expect(toChunks('1234567', 2)).toStrictEqual(['12', '34', '56', '7']); 25 | }); 26 | 27 | it('create chunks for chunk size equal 6', () => { 28 | expect(toChunks('1234567', 6)).toStrictEqual(['123456', '7']); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/toEllipsis/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/to-ellipsis` 2 | 3 | Truncates the input text to the desired length. 4 | 5 | **Installation** 6 | `npm i @plexis/to-ellipsis` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toEllipsis from '@plexis/to-ellipsis'; 12 | 13 | toEllipsis('foo'); // retruns 'foo' 14 | toEllipsis('foo', 1); // retruns 'f..' 15 | toEllipsis('foo', 3); // retruns 'foo' 16 | toEllipsis('Last night I dreamt I went to Manderley again.', 5); // retruns 'Last ...' 17 | ``` 18 | 19 | ## Aliases 20 | 21 | ```javascript 22 | import toEllipsis from '@plexis/to-ellipsis'; 23 | import {toEllipsis, truncate, fit} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/toEllipsis/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-ellipsis", 3 | "version": "0.0.22", 4 | "description": "Truncates the input text to the desired length.", 5 | "keywords": [ 6 | "utility", 7 | "string", 8 | "truncate" 9 | ], 10 | "author": "protob ", 11 | "homepage": "https://github.com/plexis-js/plexis.git", 12 | "license": "MIT", 13 | "main": "dist/index.js", 14 | "module": "dist/index.esm.js", 15 | "jsnext:main": "./src/index.js", 16 | "files": [ 17 | "dist", 18 | "src" 19 | ], 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/plexis-js/plexis.git" 26 | }, 27 | "bugs": { 28 | "url": "https://github.com/plexis-js/plexis/issues" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/toEllipsis/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Truncates the input text to the desired length. 3 | * @param {String} string 4 | * @param {Number} limit 5 | * @example 6 | * toEllipsis('foo'); //=> 'foo' 7 | * toEllipsis('foo', 1); // => 'f..' 8 | * toEllipsis('foo', 3); // => 'foo' 9 | * toEllipsis('Last night I dreamt I went to Manderley again.', 5); // => 'Last ...' 10 | */ 11 | 12 | const toEllipsis = (string, limit) => { 13 | if (isNaN(limit)) return string; 14 | const suffix = string.length <= limit ? '' : '...'; 15 | return string.substring(0, limit) + suffix; 16 | }; 17 | 18 | export default toEllipsis; 19 | -------------------------------------------------------------------------------- /packages/toEllipsis/test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import toEllipsis from '../src'; 4 | 5 | describe('@plexis/toEllipsis', () => { 6 | it('should retrun ...', () => { 7 | expect(toEllipsis('foo', 0)).toBe('...'); 8 | }); 9 | it('should retrun foo', () => { 10 | expect(toEllipsis('foo')).toBe('foo'); 11 | }); 12 | it('should retrun foo', () => { 13 | expect(toEllipsis('foo', Infinity)).toBe('foo'); 14 | }); 15 | it('should retrun foo', () => { 16 | expect(toEllipsis('foo', 3)).toBe('foo'); 17 | }); 18 | it('should retrun Last ...', () => { 19 | expect(toEllipsis('Last night I dreamt I went to Manderley again.', 5)).toBe('Last ...'); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/toHuman/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/to-human` 2 | 3 | Converts a string into a human readable text 4 | 5 | ## Installation 6 | 7 | `npm i @plexis/to-human` 8 | 9 | ## Usage 10 | 11 | ```javascript 12 | import toHuman from '@plexis/to-human'; 13 | 14 | toHuman('foo'); // => 'Foo' 15 | toHuman('foo bar'); // => 'Foo bar' 16 | toHuman(' foo-bar baz quxQuux corge_grault GarplyWaldo'); // => 'Foo bar baz qux quux corge grault garply waldo' 17 | toHuman(' foo-bar-baz qux quux'); // => 'Foo bar baz qux quux' 18 | ``` 19 | 20 | ## Aliases 21 | 22 | ```javascript 23 | import toHuman from '@plexis/to-human'; 24 | import {toHuman, humanize} from 'plexis'; 25 | ``` 26 | -------------------------------------------------------------------------------- /packages/toHuman/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-human", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "description": "Converts a string into a human readable text", 8 | "keywords": [ 9 | "utility", 10 | "string", 11 | "parse", 12 | "format", 13 | "validate" 14 | ], 15 | "author": "Angel Gonzalez ", 16 | "homepage": "https://github.com/plexis-js/plexis#readme", 17 | "license": "MIT", 18 | "files": [ 19 | "lib" 20 | ], 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git+https://github.com/plexis-js/plexis.git" 27 | }, 28 | "bugs": { 29 | "url": "https://github.com/plexis-js/plexis/issues" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/toHuman/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string into a human readable text 3 | * @param {String} text 4 | * @example 5 | * toHuman('foo') // returns 'Foo' 6 | * toHuman('foo bar') // returns 'Foo bar' 7 | * toHuman(' foo-bar-baz qux quux') // returns 'Foo bar baz qux quux' 8 | */ 9 | const toHuman = text => 10 | text 11 | .trim() 12 | .replace(/_|-/g, ' ') 13 | .trim() 14 | .replace(/([A-Z])/g, word => ' ' + word.toLowerCase()) 15 | .trim() 16 | .replace(/^[a-z]/g, first => first.toUpperCase()) 17 | .replace(/\s\s+/g, ' ') 18 | .trim(); 19 | 20 | export default toHuman; 21 | -------------------------------------------------------------------------------- /packages/toHuman/test/index.js: -------------------------------------------------------------------------------- 1 | import toHuman from '../src'; 2 | 3 | describe('@plexis/to-human', () => { 4 | it('Converts a string into a human readable text', () => { 5 | expect(toHuman('foo')).toBe('Foo'); 6 | expect(toHuman('foo bar')).toBe('Foo bar'); 7 | expect(toHuman(' foo-bar baz quxQuux corge_grault GarplyWaldo')).toBe( 8 | 'Foo bar baz qux quux corge grault garply waldo' 9 | ); 10 | expect(toHuman(' foo-bar-baz qux quux')).toBe('Foo bar baz qux quux'); 11 | expect(toHuman('fooBar qux-core - _ ')).toBe('Foo bar qux core'); 12 | expect(toHuman('foo_')).toBe('Foo'); 13 | expect(toHuman('foo-')).toBe('Foo'); 14 | expect(toHuman('_foo')).toBe('Foo'); 15 | expect(toHuman('Foo bar')).toBe('Foo bar'); 16 | expect(toHuman('Foo')).toBe('Foo'); 17 | expect(toHuman(' foo ')).toBe('Foo'); 18 | expect(toHuman(' Foo ')).toBe('Foo'); 19 | expect(toHuman('-Foo ')).toBe('Foo'); 20 | expect(toHuman('Foo Bar foo')).toBe('Foo bar foo'); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /packages/toLower/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/toLower` 2 | 3 | Lowercase the first letter of the given string. 4 | 5 | **Installation** 6 | `npm i @plexis/to-lower` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toLower from '@plexis/to-lower'; 12 | 13 | toLower('Foo Bar', false); // returns 'foo Bar' 14 | toLower('Foo Bar', true); // returns 'foo bar' 15 | toLower('FOO BAR', false); // returns 'fOO BAR' 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {toLower} from 'plexis'; 22 | import {toFirstLower} from 'plexis'; 23 | import {decapitalize} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/toLower/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-lower", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "4doge https://github.com/4doge" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toLower/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Lowercase the first letter of the given string. 3 | * @param {String} text 4 | * @param {Boolean} isLowecase 5 | * @example 6 | * toLower('Foo Bar', false) // returns 'foo Bar' 7 | * toLower('Foo Bar', true) // returns 'foo bar' 8 | */ 9 | const toLower = (text, isLower) => { 10 | const s = isLower ? text.slice(1).toLowerCase() : text.slice(1); 11 | return text.charAt(0).toLowerCase() + s; 12 | }; 13 | 14 | export default toLower; 15 | -------------------------------------------------------------------------------- /packages/toLower/test/index.js: -------------------------------------------------------------------------------- 1 | import toLower from '../src'; 2 | 3 | it('lowercase only the first letter in single word', () => { 4 | expect(toLower('HeLLo', false)).toBe('heLLo'); 5 | }); 6 | 7 | it('lowercase only the first letter in multiword sentense', () => { 8 | expect(toLower('HeLLo WorLD', false)).toBe('heLLo WorLD'); 9 | }); 10 | 11 | it('lowercase all single word letters', () => { 12 | expect(toLower('HeLLo', true)).toBe('hello'); 13 | }); 14 | 15 | it('lowercase all multiword sentense letters', () => { 16 | expect(toLower('HeLLo WorLD', true)).toBe('hello world'); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/toPascalCase/README.md: -------------------------------------------------------------------------------- 1 | ## `toPascalCase` 2 | 3 | Converts the input text to pascal case 4 | 5 | `npm i @plexis/name-of-the-module` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import toPascalCase from '@plexis/to-pascal-case'; 11 | 12 | toPascalCase('Cool'); 13 | // => 'Cool' 14 | 15 | toPascalCase('cool mate'); 16 | // => 'CoolMate' 17 | 18 | toPascalCase('Hey how are you today?'); 19 | // => 'HeyHowAreYouToday' 20 | 21 | toPascalCase('camelCase'); 22 | // => 'CamelCase' 23 | 24 | toPascalCase('kebab-case'); 25 | // => KebabCase 26 | ``` 27 | 28 | **Aliases** 29 | 30 | ```javascript 31 | import toPascalCase from '@plexis/to-pascal-case'; 32 | import {toPascalCase, classify} from 'plexis'; 33 | ``` 34 | -------------------------------------------------------------------------------- /packages/toPascalCase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-pascal-case", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Jack Chapman " 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toPascalCase/src/index.js: -------------------------------------------------------------------------------- 1 | // to be replaced with @plexis/toCamelCase 2 | const toCamelCase = text => { 3 | const lowerUpper = (letter, index) => { 4 | return index === 0 ? letter.toLowerCase() : letter.toUpperCase(); 5 | }; 6 | const wordPatt = /^\w|[A-Z]|\b\w/g; 7 | const symbolPatt = /[^a-zA-Z0-9]/g; 8 | return text 9 | .trim() 10 | .replace(wordPatt, lowerUpper) 11 | .replace(symbolPatt, ''); 12 | }; 13 | 14 | /** 15 | * @description Convert a word to pascal case 16 | * @param {String} text 17 | * @example 18 | * toPascalCase('foo') // returns 'Foo' 19 | * toPred('foo bar') // returns 'FooBar' 20 | * toPred('FOO BAR BAZ') // returns 'FooBarBaz' 21 | */ 22 | const toPascalCase = text => { 23 | const result = toCamelCase(text); 24 | return result.charAt(0).toUpperCase() + result.substr(1); 25 | }; 26 | 27 | export default toPascalCase; 28 | -------------------------------------------------------------------------------- /packages/toPascalCase/test/index.js: -------------------------------------------------------------------------------- 1 | import toPascalCase from '../src'; 2 | 3 | it('Works with single characters', () => { 4 | expect(toPascalCase('h')).toBe('H'); 5 | }); 6 | 7 | it('Works will full words', () => { 8 | expect(toPascalCase('hello')).toBe('Hello'); 9 | }); 10 | 11 | it('Works with strange cases on a single word', () => { 12 | expect(toPascalCase('hEllO')).toBe('HEllO'); 13 | }); 14 | 15 | it('Works with multiple words', () => { 16 | expect(toPascalCase('Hello there')).toBe('HelloThere'); 17 | }); 18 | 19 | it('Removes symbols', () => { 20 | expect(toPascalCase('@@@hello@@@')).toBe('Hello'); 21 | }); 22 | 23 | it('Works with long strings', () => { 24 | expect(toPascalCase('This is a long string compared to the other tests')).toBe( 25 | 'ThisIsALongStringComparedToTheOtherTests' 26 | ); 27 | }); 28 | 29 | it('Converts camelCase properly', () => { 30 | expect(toPascalCase('camelCase')).toBe('CamelCase'); 31 | }); 32 | 33 | it('Converts kebab-case properly', () => { 34 | expect(toPascalCase('kebab-case')).toBe('KebabCase'); 35 | }); 36 | -------------------------------------------------------------------------------- /packages/toPlural/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/to-plural` 2 | 3 | Converts a word to its plural form 4 | 5 | ## Installation 6 | 7 | `npm i @plexis/to-plural` 8 | 9 | ## Usage 10 | 11 | ```javascript 12 | import toPlural from '@plexis/to-plural'; 13 | 14 | toPlural('example'); // => 'examples' 15 | toPlural('example', 10); // => 'examples' 16 | toPlural('example', 1); // => 'example' 17 | toPlural('example', 'examplez', 10); // => 'examplez' 18 | toPlural('example', 'examplez', 1); // => 'example' 19 | ``` 20 | 21 | ## Aliases 22 | 23 | ```javascript 24 | import toPlural from '@plexis/to-plural'; 25 | import {toPlural, pluralize} from 'plexis'; 26 | ``` 27 | -------------------------------------------------------------------------------- /packages/toPlural/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-plural", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "description": "Converts a word to its plural form", 8 | "keywords": [ 9 | "utility", 10 | "string", 11 | "parse", 12 | "format", 13 | "validate" 14 | ], 15 | "author": "shilangyu ", 16 | "homepage": "https://github.com/plexis-js/plexis#readme", 17 | "license": "MIT", 18 | "files": [ 19 | "lib" 20 | ], 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git+https://github.com/plexis-js/plexis.git" 27 | }, 28 | "bugs": { 29 | "url": "https://github.com/plexis-js/plexis/issues" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/toPlural/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a word to its plural form 3 | * @param {String} word 4 | * @param {String} pluralForm 5 | * @param {Number} count 6 | * @returns {String} pluralized word 7 | * @example 8 | * toPlural('example'); // => 'examples' 9 | * toPlural('example', 10); // => 'examples' 10 | * toPlural('example', 1); // => 'example' 11 | * toPlural('example', 'examplez', 10); // => 'examplez' 12 | * toPlural('example', 'examplez', 1); // => 'example' 13 | */ 14 | 15 | const toPlural = (word, ...rest) => { 16 | if (rest.length === 1 && typeof rest[0] === 'string') return word; 17 | 18 | const isPlural = rest.length === 0 || Math.abs(rest[rest.length - 1]) !== 1; 19 | const pluralForm = rest.length === 2 ? rest[0] : `${word}s`; 20 | 21 | return isPlural ? pluralForm : word; 22 | }; 23 | 24 | export default toPlural; 25 | -------------------------------------------------------------------------------- /packages/toPlural/test/index.js: -------------------------------------------------------------------------------- 1 | import toPlural from '../src'; 2 | 3 | describe('@plexis/to-plural', () => { 4 | it('converts a given string to its plural form', () => { 5 | expect(toPlural('example')).toBe('examples'); 6 | expect(toPlural('example', 10)).toBe('examples'); 7 | expect(toPlural('example', 1)).toBe('example'); 8 | expect(toPlural('example', 0)).toBe('examples'); 9 | expect(toPlural('example', -1)).toBe('example'); 10 | expect(toPlural('example', 'examplez', 10)).toBe('examplez'); 11 | expect(toPlural('example', 'examplez', 0)).toBe('examplez'); 12 | expect(toPlural('example', 'examplez', 1)).toBe('example'); 13 | expect(toPlural('example', 'examplez', -1)).toBe('example'); 14 | expect(toPlural('example', 'examplez')).toBe('example'); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/toPred/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/toPred` 2 | 3 | Converts a string to its equivalent predecessor. 4 | 5 | **Installation** 6 | `npm i @plexis/to-pred` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toPred from '@plexis/to-pred'; 12 | 13 | toPred('b'); // returns 'a' 14 | toPred('B'); // returns 'A' 15 | toPred('BCD'); // returns 'ABC' 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {toPred} from 'plexis'; 22 | import {toPredecessor} from 'plexis'; 23 | ``` 24 | -------------------------------------------------------------------------------- /packages/toPred/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-pred", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Theodore Vorillas (https://vorillaz.com)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toPred/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string to its equivalent predecessor 3 | * @param {String} text 4 | * @example 5 | * toPred('b') // returns 'a' 6 | * toPred('B') // returns 'A' 7 | * toPred('BCD') // returns 'ABC' 8 | */ 9 | const toPred = text => 10 | text 11 | .split('') 12 | .map(s => String.fromCharCode(s.charCodeAt(0) - 1)) 13 | .join(''); 14 | 15 | export default toPred; 16 | -------------------------------------------------------------------------------- /packages/toPred/test/index.js: -------------------------------------------------------------------------------- 1 | import toPred from '../src'; 2 | 3 | it('converts a single char to its predecessor', () => { 4 | expect(toPred('b')).toBe('a'); 5 | expect(toPred('B')).toBe('A'); 6 | }); 7 | 8 | it('converts a sentence to its predecessor', () => { 9 | expect(toPred('LoremIpsum')).toBe('KnqdlHortl'); 10 | }); 11 | 12 | it('converts a sentence its predecessor for other languages as well', () => { 13 | expect(toPred('κείμενο')).toBe('ιδήλδμξ'); 14 | expect(toPred('публикация')).toBe('отакзйЯхзю'); 15 | expect(toPred('台匿名的打印机刻意打乱了')).toBe('可匾同皃扒卯朹刺愎扒买亅'); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/toSnakeCase/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/toSnakeCase` 2 | 3 | Converts the input text to camelCase. 4 | 5 | **Installation** 6 | `npm i @plexis/to-snake-case` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toSnakeCase from '@plexis/to-snake-case'; 12 | 13 | toSnakeCase('Cool'); // => 'cool' 14 | toSnakeCase('cool mate'); // => 'cool_mate' 15 | toSnakeCase('Hey how are you today?'); // => 'hey_how_are_you_today' 16 | toSnakeCase('PascalCase'); // => 'pascal_case' 17 | toSnakeCase('kebab-case'); // => kebab_case 18 | ``` 19 | 20 | **Aliases** 21 | 22 | ```javascript 23 | import {toSnakeCase} from 'plexis'; 24 | import {snakeCase} from 'plexis'; 25 | ``` 26 | -------------------------------------------------------------------------------- /packages/toSnakeCase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-snake-case", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Gopi Krishna (https://bgopikrishna.me)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toSnakeCase/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string to snake case 3 | * @param {String} text 4 | * @returns {String} snake case text 5 | * @example 6 | * toSnakeCase('Cool') => 'cool' 7 | * toSnakeCase('cool mate') => 'cool_mate' 8 | * toSnakeCase('Hey how are you today?') => 'hey_how_are_you_today' 9 | * toSnakeCase('PascalCase') => 'pascal_case' 10 | * toSnakeCase('kebab-case') => 'kebab_case' 11 | */ 12 | 13 | const toSnakeCase = string => { 14 | const removeSym = (letter, index, string) => { 15 | return string.length - 1 === index ? '' : '_'; 16 | }; 17 | const pascalAndCamelParser = l => { 18 | return (l[0] + '_' + l[1]).toLowerCase(); 19 | }; 20 | 21 | const wordPatt = /[\w]([A-Z])/g; 22 | const symbolPatt = /[^a-zA-Z0-9]/g; 23 | let result = string 24 | .trim() 25 | .replace(wordPatt, pascalAndCamelParser) 26 | .replace(symbolPatt, removeSym) 27 | .toLowerCase(); 28 | 29 | return result; 30 | }; 31 | 32 | export default toSnakeCase; 33 | -------------------------------------------------------------------------------- /packages/toSnakeCase/test/index.js: -------------------------------------------------------------------------------- 1 | import toSnakeCase from '../src'; 2 | 3 | it('converts a given string to snake case', () => { 4 | expect(toSnakeCase('Cool')).toBe('cool'); 5 | expect(toSnakeCase('cool mate')).toBe('cool_mate'); 6 | expect(toSnakeCase('Hey how are you today?')).toBe('hey_how_are_you_today'); 7 | expect(toSnakeCase('PascalCase')).toBe('pascal_case'); 8 | expect(toSnakeCase('kebab-case')).toBe('kebab_case'); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/toSucc/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/toSucc` 2 | 3 | Converts a string to its equivalent successor. 4 | 5 | **Installation** 6 | `npm i @plexis/to-succ` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toSucc from '@plexis/to-succ'; 12 | 13 | toSucc('a'); // returns 'b' 14 | toSucc('A'); // returns 'B' 15 | toSucc('ABCD'); // returns 'BCDE' 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {toSucc} from 'plexis'; 22 | import {toSuccessor} from 'plexis'; 23 | ``` 24 | -------------------------------------------------------------------------------- /packages/toSucc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-succ", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Theodore Vorillas (https://vorillaz.com)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toSucc/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string to its equivalent successor 3 | * @param {String} text 4 | * @example 5 | * toSucc('a') // returns 'b' 6 | * toSucc('A') // returns 'B' 7 | * toSucc('ABCD') // returns 'BCDE' 8 | */ 9 | 10 | const toSucc = text => 11 | text 12 | .split('') 13 | .map(s => String.fromCharCode(s.charCodeAt(0) + 1)) 14 | 15 | .join(''); 16 | 17 | export default toSucc; 18 | -------------------------------------------------------------------------------- /packages/toSucc/test/index.js: -------------------------------------------------------------------------------- 1 | import toSucc from '../src'; 2 | 3 | it('converts a single char to its successor', () => { 4 | expect(toSucc('a')).toBe('b'); 5 | expect(toSucc('A')).toBe('B'); 6 | }); 7 | 8 | it('converts a sentence to its successor', () => { 9 | expect(toSucc('LoremIpsum')).toBe('MpsfnJqtvn'); 10 | }); 11 | 12 | it('converts a sentence for other languages', () => { 13 | expect(toSucc('κείμενο')).toBe('λζΰνζξπ'); 14 | expect(toSucc('публикация')).toBe('рфвмйлбчйѐ'); 15 | expect(toSucc('台匿名的打印机刻意打乱了')).toBe('叱區后皅扔危朻刼愐扔乲亇'); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/toSwap/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/toSwap` 2 | 3 | Swaps every character with the next one in a given string. 4 | 5 | `npm i @plexis/to-swap` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import toSwap from '@plexis/to-swap'; 11 | 12 | toSwap('ab'); // returns 'ba' 13 | toSwap('abc'); // returns 'bac' 14 | toSwap('abcd'); // returns 'badc' 15 | toSwap('a b'); // returns ' ab' 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {toSwap} from 'plexis'; 22 | import {swap} from 'plexis'; 23 | ``` 24 | -------------------------------------------------------------------------------- /packages/toSwap/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-swap", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "David Medeiros " 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toSwap/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Swaps every character in a string, until the end of the string 3 | * @param {String} string 4 | * @example 5 | * toSwap('ab') // returns 'ab' 6 | * toSwap('a b') // returns ' ab' 7 | * toSwap('abcd') // returns 'badc' 8 | * @returns {String} reordered letters 9 | */ 10 | const toSwap = string => { 11 | var arr = string.split(''); 12 | arr.forEach((current, index, array) => { 13 | if (index % 2 == 0) { 14 | array[index] = array[index + 1]; 15 | array[index + 1] = current; 16 | } 17 | }); 18 | return arr.join(''); 19 | }; 20 | 21 | export default toSwap; 22 | -------------------------------------------------------------------------------- /packages/toSwap/test/index.js: -------------------------------------------------------------------------------- 1 | import toSwap from '../src'; 2 | 3 | it('Swap only small strings', () => { 4 | expect(toSwap('ab')).toBe('ba'); 5 | expect(toSwap('a')).toBe('a'); 6 | }); 7 | it('Swap an odd number of letters', () => { 8 | expect(toSwap('abc')).toBe('bac'); 9 | expect(toSwap('abcd')).toBe('badc'); 10 | }); 11 | it('Swap with spaces', () => { 12 | expect(toSwap('a b')).toBe(' ab'); 13 | expect(toSwap('ab cd')).toBe('bac d'); 14 | }); 15 | it('Swap Random Characters', () => { 16 | expect(toSwap('1;3')).toBe(';13'); 17 | expect(toSwap('.,][')).toBe(',.[]'); 18 | }); 19 | it('Empty string case', () => { 20 | expect(toSwap('')).toBe(''); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/toSwapCase/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/to-swap-case` 2 | 3 | Swaps lowercase to uppercase and vice versa for the input text. 4 | 5 | **Installation** 6 | `npm i @plexis/to-swap-case` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toSwapCase from '@plexis/to-swap-case'; 12 | 13 | toSwapCase('Hello WORLD'); // => 'hELLO world' 14 | toSwapCase('123 toys'); // => '123 TOYS' 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import toSwapCase from '@plexis/to-swap-case'; 21 | import {toSwapCase, swapCase} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/toSwapCase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-swap-case", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Nowtryz (https://nowtryz.net)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toSwapCase/src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Swaps lowercase to uppercase and vice versa for the input text. 5 | * @param {String} input 6 | * @returns {String} swaped text 7 | * @example 8 | * toSwapCase('Hello WORLD'); // => 'hELLO world' 9 | * toSwapCase('123 toys'); // => '123 TOYS' 10 | */ 11 | export default input => 12 | input 13 | .toString() 14 | .split('') 15 | .map(c => { 16 | const lower = c.toLocaleLowerCase(); 17 | return lower === c ? c.toLocaleUpperCase() : lower; 18 | }) 19 | .join(''); 20 | -------------------------------------------------------------------------------- /packages/toSwapCase/test/swap-case.test.js: -------------------------------------------------------------------------------- 1 | import swapCase from '../src'; 2 | 3 | describe('@plexis/to-swap-case', () => { 4 | it('Swap single char', () => { 5 | expect(swapCase('a')).toBe('A'); 6 | expect(swapCase('B')).toBe('b'); 7 | expect(swapCase('5')).toBe('5'); 8 | }); 9 | 10 | it('Swap charters of a sentence', () => { 11 | expect(swapCase('Hello WORLD')).toBe('hELLO world'); 12 | expect(swapCase('123 toys')).toBe('123 TOYS'); 13 | expect(swapCase('654 À Á Â Ã Ä Å Æ Ç È É Ê ę')).toBe('654 à á â ã ä å æ ç è é ê Ę'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/toTitle/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/toTitle` 2 | 3 | Converts a string to a title, capitalizes the first letter of each word. 4 | 5 | **Installation** 6 | `npm i @plexis/to-title` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import toTitle from '@plexis/to-title'; 12 | 13 | toTitle('this is cool mate'); // returns 'This Is Cool Mate' 14 | ``` 15 | 16 | **Aliases** 17 | 18 | ```javascript 19 | import {toTitle} from 'plexis'; 20 | import {titleize} from 'plexis'; 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/toTitle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/to-title", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Theodore Vorillas (https://vorillaz.com)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/toTitle/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Converts a string to a title, capitalizes the first letter of each word. 3 | * @param {String} text 4 | * @example 5 | * toTitle('this is cool mate') // returns 'This Is Cool Mate' 6 | */ 7 | const toTitle = text => 8 | text 9 | .toLowerCase() 10 | .split(' ') 11 | .map(s => s.charAt(0).toUpperCase() + s.substring(1)) 12 | .join(' '); 13 | 14 | export default toTitle; 15 | -------------------------------------------------------------------------------- /packages/toTitle/test/index.js: -------------------------------------------------------------------------------- 1 | import toTitle from '../src'; 2 | 3 | it('converts a sigle word sentence to a title', () => { 4 | expect(toTitle('this')).toBe('This'); 5 | }); 6 | 7 | it('converts a multiword sentence to a title', () => { 8 | expect(toTitle('this is cool mate')).toBe('This Is Cool Mate'); 9 | }); 10 | 11 | it('converts a multiword sentence to a title for any given language', () => { 12 | // lipsum.com 13 | // Greek 14 | expect( 15 | toTitle( 16 | 'Το Lorem Ipsum είναι απλά ένα κείμενο χωρίς νόημα για τους επαγγελματίες της τυπογραφίας και στοιχειοθεσίας.' 17 | ) 18 | ).toBe( 19 | 'Το Lorem Ipsum Είναι Απλά Ένα Κείμενο Χωρίς Νόημα Για Τους Επαγγελματίες Της Τυπογραφίας Και Στοιχειοθεσίας.' 20 | ); 21 | 22 | // French 23 | expect(toTitle("Est qu'il possède une distribution de l'imprimerie depuis")).toBe( 24 | "Est Qu'il Possède Une Distribution De L'imprimerie Depuis" 25 | ); 26 | 27 | // Spanish 28 | expect(toTitle('el texto de relleno estándar de las industrias desde el año 1500')).toBe( 29 | 'El Texto De Relleno Estándar De Las Industrias Desde El Año 1500' 30 | ); 31 | }); 32 | -------------------------------------------------------------------------------- /packages/when/README.md: -------------------------------------------------------------------------------- 1 | ## `when` 2 | 3 | `when` is used for checking and chaining within the composition for supercharged functions. 4 | 5 | `npm i @plexis/when` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import compose from '@plexis/compose'; 11 | import when from '@plexis/when'; 12 | 13 | const inc = x => x + 1; 14 | const add = (x, y) => x + y; 15 | const setToZero = () => 0; 16 | 17 | const compose = (...fns) => x => fns.reduce((r, f) => f(r), x); 18 | const when = (cond, f) => x => (cond(x) ? f(x) : x); 19 | 20 | const ops = compose( 21 | inc, 22 | x => add(x, 2), 23 | when(num => num > 0, compose(setToZero)) 24 | ); 25 | 26 | ops(1); // returns 0 27 | ops(100); // returns 0 28 | ops(-100); // returns -97 29 | ``` 30 | 31 | **Aliases** 32 | 33 | ```javascript 34 | import when from '@plexis/when'; 35 | import {when} from 'plexis'; 36 | ``` 37 | -------------------------------------------------------------------------------- /packages/when/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/when", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/when/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Is used for checking and chaining within the composition for supercharged functions. 3 | * @param {Function|Boolean} [checking] A function or condition to check. 4 | * @param {Function} [func] The function to invoke. 5 | * @returns {Function} Returns the new composite function. 6 | * @example 7 | * _when(num => num < 0, () => 0)(-1) // returns 0 8 | */ 9 | const _when = (checking, func) => value => { 10 | if (checking === true || (typeof checking === 'function' && checking(value))) { 11 | return func(value); 12 | } 13 | return value; 14 | }; 15 | 16 | export default _when; 17 | -------------------------------------------------------------------------------- /packages/when/test/index.js: -------------------------------------------------------------------------------- 1 | import _when from '../src'; 2 | 3 | it('executes the function if the condition is a boolean and true', () => { 4 | const mock = jest.fn(); 5 | _when(true, mock)(1); 6 | expect(mock).toHaveBeenCalledTimes(1); 7 | expect(mock).toHaveBeenCalledWith(1); 8 | }); 9 | 10 | it("doesn't execute the function if the condition is a boolean and false", () => { 11 | const mock = jest.fn(); 12 | _when(false, mock)(1); 13 | expect(mock).toHaveBeenCalledTimes(0); 14 | }); 15 | 16 | it('executes the function if the condition is a function and evaluates to true', () => { 17 | const mock = jest.fn(); 18 | _when(x => x > 0, mock)(1); 19 | expect(mock).toHaveBeenCalledTimes(1); 20 | expect(mock).toHaveBeenCalledWith(1); 21 | }); 22 | 23 | it("doesn't execute the function if the condition is a function and evaluates to false", () => { 24 | const mock = jest.fn(); 25 | _when(x => x > 0, mock)(-1); 26 | expect(mock).toHaveBeenCalledTimes(0); 27 | }); 28 | -------------------------------------------------------------------------------- /packages/withoutDiacritics/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/withoutDiacritics` 2 | 3 | Cleanups a string from diacritics. 4 | 5 | **Installation** 6 | `npm i @plexis/without-diacritics` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import withoutDiacritics from '@plexis/without-diacritics'; 12 | 13 | withoutDiacritics('áéíóú'); // returns 'aeiou' 14 | ``` 15 | 16 | **Aliases** 17 | 18 | ```javascript 19 | import {withoutDiacritics} from 'plexis'; 20 | import {cleanDiacritics} from 'plexis'; 21 | import {removeDiacritics} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/withoutDiacritics/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/without-diacritics", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Theodore Vorillas (https://vorillaz.com)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/withoutDiacritics/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Cleanups a string from diacritics. 3 | * @param {String} text 4 | * @example 5 | * withoutDiacritics('áéíóú') // returns 'aeiou' 6 | */ 7 | const withoutDiacritics = text => text.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); 8 | 9 | export default withoutDiacritics; 10 | -------------------------------------------------------------------------------- /packages/withoutDiacritics/test/index.js: -------------------------------------------------------------------------------- 1 | import withoutDiacritics from '../src'; 2 | 3 | it('removes any diacritics for Galician', () => { 4 | expect(withoutDiacritics('áéíóú')).toBe('aeiou'); 5 | }); 6 | 7 | it('removes any diacritics for Greek', () => { 8 | expect(withoutDiacritics('Άά Έέ Ήή Ίί Όό Ύύ Ώώ ΐ ΰ Ϊϊ Ϋϋ')).toBe( 9 | 'Αα Εε Ηη Ιι Οο Υυ Ωω ι υ Ιι Υυ' 10 | ); 11 | }); 12 | 13 | it('removes any diacritics for Latvian', () => { 14 | expect(withoutDiacritics('āēīūčģķļņšž')).toBe('aeiucgklnsz'); 15 | }); 16 | 17 | it('removes any diacritics for Czech', () => { 18 | expect(withoutDiacritics('č ď ě ň ř š ť ž')).toBe('c d e n r s t z'); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/withoutHTML/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/withoutHTML` 2 | 3 | Removes HTML tags from the input text. 4 | 5 | **Installation** 6 | `npm i @plexis/without-html` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import withoutHTML from '@plexis/without-html'; 12 | 13 | withoutHTML('Hello world'); // => 'Hello world' 14 | withoutHTML('

Hello

world'); // => ' world' 15 | withoutHTML('

'

Hello world

'); // => '' 17 | withoutHTML('

from the underground'); // => ' from the underground' 18 | ``` 19 | 20 | **Aliases** 21 | 22 | ```javascript 23 | import withoutHTML from '@plexis/without-html'; 24 | import {withoutHTML, removeHTML} from 'plexis'; 25 | ``` 26 | -------------------------------------------------------------------------------- /packages/withoutHTML/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/without-html", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Gopi Krishna (https://bgopikrishna.me)" 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "string", 18 | "parse", 19 | "format", 20 | "validate" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/withoutHTML/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Remove HTML tags from the input text 3 | * @param {String} text 4 | * @returns {String} text without HTML 5 | * @example 6 | * withoutHTML('Hello world') => 'Hello world' 7 | * withoutHTML('

Hello

world') => ' world' 8 | * withoutHTML('

'

Hello world

') => '' 10 | * withoutHTML('

from the underground ') => ' from the underground' 11 | */ 12 | 13 | const withoutHTML = string => { 14 | const wordPatt = /[^>]+>/g; 15 | const stringWithOutHtml = string.replace(wordPatt, ''); 16 | 17 | return stringWithOutHtml; 18 | }; 19 | 20 | export default withoutHTML; 21 | -------------------------------------------------------------------------------- /packages/withoutHTML/test/index.js: -------------------------------------------------------------------------------- 1 | import withoutHTML from '../src'; 2 | 3 | it('Remove HTML tags from the input text', () => { 4 | expect(withoutHTML('Hello world')).toBe('Hello world'); 5 | expect(withoutHTML('

Hello

world')).toBe(' world'); 6 | expect(withoutHTML('

Hello world

')).toBe(''); 8 | expect(withoutHTML('

from the underground')).toBe( 9 | ' from the underground' 10 | ); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/withoutIndent/README.md: -------------------------------------------------------------------------------- 1 | ## `withoutIndent` 2 | 3 | Removes leading whitespaces from each line in a string 4 | 5 | `npm i @plexis/without-indent` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import withoutIndent from '@plexis/without-indent'; 11 | 12 | withoutIndent('\t\t\tHello World'); // returns 'Hello World' 13 | withoutIndent('\n\tHello\n\tWorld'); // returns '\nHello\nWorld' 14 | ``` 15 | 16 | **Aliases** 17 | 18 | ```javascript 19 | import {removeIndent} from 'plexis'; 20 | import {dedent} from 'plexis'; 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/withoutIndent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/without-indent", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/withoutIndent/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Removes leading whitespaces from every line in the given string 3 | * @param {String} text 4 | * @param {Number} [removeUpTo] - Specifies how many whitespaces to remove 5 | * @example 6 | * 7 | * withoutIndent('\t\t\tHello World'); // returns 'Hello World' 8 | * withoutIndent('\n\tHello\n\tWorld'); // returns '\nHello\nWorld' 9 | * withoutIndent('\n\tHello\n\t\t\tWorld', 2); // returns '\nHello\n\tWorld' 10 | */ 11 | const withoutIndent = (text, removeUpTo) => { 12 | if (removeUpTo <= 0) return text; 13 | const howMany = typeof removeUpTo === 'number' ? `{1,${removeUpTo}}` : '+'; 14 | const regex = new RegExp(`^[ \\t\\r]${howMany}|(?<=\\n+)[ \\t\\r]${howMany}`, 'g'); 15 | return text.replace(regex, ''); 16 | }; 17 | 18 | export default withoutIndent; 19 | -------------------------------------------------------------------------------- /packages/withoutIndent/test/index.js: -------------------------------------------------------------------------------- 1 | import withoutIndent from '../src'; 2 | 3 | it('removes an indent from the front', () => { 4 | expect(withoutIndent('\tHello')).toBe('Hello'); 5 | expect(withoutIndent('\rHello')).toBe('Hello'); 6 | expect(withoutIndent(' Hello')).toBe('Hello'); 7 | }); 8 | 9 | it("doesn't remove newline characters", () => { 10 | expect(withoutIndent('\nHello')).toBe('\nHello'); 11 | }); 12 | 13 | it("doesn't remove anything when there's no indent", () => { 14 | expect(withoutIndent('Hello')).toBe('Hello'); 15 | }); 16 | 17 | it('removes multiple indents.', () => { 18 | expect(withoutIndent('\t\t\tHello')).toBe('Hello'); 19 | }); 20 | 21 | it('removes indents on multiple lines', () => { 22 | expect(withoutIndent('\t\tHello\n\t\tWorld')).toBe('Hello\nWorld'); 23 | }); 24 | 25 | it("doesn't remove indents that aren't at the beginning of a line.", () => { 26 | expect(withoutIndent('Hello\t')).toBe('Hello\t'); 27 | }); 28 | 29 | it('removes only specified amount of indents', () => { 30 | expect(withoutIndent('\t\t\t\tHello', 3)).toBe('\tHello'); 31 | }); 32 | 33 | it("doesn't remove extra characters when amount specified exceeds indents", () => { 34 | expect(withoutIndent('\t\tHello', 3)).toBe('Hello'); 35 | }); 36 | 37 | it("doesn't remove indents when 0 is given as amount", () => { 38 | expect(withoutIndent('\tHello', 0)).toBe('\tHello'); 39 | }); 40 | 41 | it('removes a mix of different indent characters', () => { 42 | expect(withoutIndent('\t \rHello')).toBe('Hello'); 43 | }); 44 | --------------------------------------------------------------------------------

')).toBe(4); 11 | }); 12 | 13 | it('Levenshtein Distance should be the same for the same strings', () => { 14 | expect(distance('flaw', 'lawn')).toBe(2); 15 | expect(distance('lawn', 'flaw')).toBe(2); 16 | expect(distance('encyclopedia', 'cat')).toBe(11); 17 | expect(distance('cat', 'encyclopedia')).toBe(11); 18 | }); 19 | 20 | it('Should return a Levenshtein Distance of 0 for non-strings', () => { 21 | expect(distance(x => 0, 'back')).toBe(0); 22 | expect(distance(9, 'back')).toBe(0); 23 | expect(distance(45, 0)).toBe(0); 24 | }); 25 | 26 | it('Should return a number', () => { 27 | expect(typeof distance('book', 'back')).toBe('number'); 28 | }); 29 | -------------------------------------------------------------------------------- /packages/endsWith/README.md: -------------------------------------------------------------------------------- 1 | # `endsWith` 2 | 3 | Checks whether the input text ends with the given pattern 4 | 5 | `npm i @plexis/ends-with` 6 | 7 | ## Usage 8 | 9 | ```javascript 10 | import endsWith from '@plexis/ends-with'; 11 | 12 | const txt = 'This is me'; 13 | 14 | endsWith(txt, 'is me'); // true 15 | endsWith(txt, 'is m', txt.length - 1); // true 16 | endsWith(txt, 'is m', txt.length); // false 17 | endsWith(txt, 'Foo'); // false 18 | ``` 19 | -------------------------------------------------------------------------------- /packages/endsWith/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/ends-with", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | }, 26 | "dependencies": { 27 | "@plexis/is-string": "^0.0.22" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/endsWith/src/index.js: -------------------------------------------------------------------------------- 1 | import isString from '@plexis/is-string'; 2 | 3 | /** 4 | * @description Checks whether the input text ends with the given pattern 5 | * 6 | * @param {String} text - String to be tested 7 | * @param {String|Regex} pattern - Pattern to be checked against text 8 | * @param {Number} startingPosition, optional - The position of the end of the string 9 | * 10 | * @example 11 | * 12 | * endsWith('This is me', 'is me') // true 13 | * endsWith('This is me', 'is m', ('This is me').length - 1) // true 14 | * endsWith('This is me', 'is m', ('This is me').length) // false 15 | * endsWith('This is me', 'Foo') // false 16 | */ 17 | const endsWith = (text, pattern, startingPosition = text.length) => { 18 | if (isString(pattern)) { 19 | return text.endsWith(pattern, startingPosition); 20 | } 21 | 22 | if (pattern instanceof RegExp) { 23 | const stringPattern = String(pattern); 24 | const flags = stringPattern.slice(stringPattern.lastIndexOf('/') + 1); 25 | 26 | const leadingAndTrailingSlashes = new RegExp(`(?:^\/|\/${flags}$)`, 'g'); 27 | const internalRegexString = stringPattern.replace(leadingAndTrailingSlashes, ''); 28 | const endsWithRegex = new RegExp(`${internalRegexString}$`, flags); 29 | 30 | return endsWithRegex.test(text.slice(0, startingPosition)); 31 | } 32 | 33 | return false; 34 | }; 35 | 36 | export default endsWith; 37 | -------------------------------------------------------------------------------- /packages/endsWith/test/ends-with.test.js: -------------------------------------------------------------------------------- 1 | import endsWith from '../src'; 2 | 3 | describe('@plexis/ends-with', () => { 4 | const baseString = 'A normal string'; 5 | 6 | it('receives strings as pattern', () => { 7 | expect(endsWith(baseString, 'string')).toBe(true); 8 | expect(endsWith(baseString, 'normal')).toBe(false); 9 | }); 10 | 11 | it('receives regex as pattern', () => { 12 | expect(endsWith(baseString, /strr*[r|i]ng/)).toBe(true); 13 | expect(endsWith(baseString, /normal\/\s/m)).toBe(false); 14 | }); 15 | 16 | it('takes starting position into consideration for string', () => { 17 | expect(endsWith(baseString, 'normal', 'A normal'.length)).toBe(true); 18 | expect(endsWith(baseString, 'string', 'A normal'.length)).toBe(false); 19 | }); 20 | 21 | it('takes starting position into consideration for regex', () => { 22 | expect(endsWith(baseString, /n.rmal/, 'A normal'.length)).toBe(true); 23 | expect(endsWith(baseString, /string/, 'A normal'.length)).toBe(false); 24 | }); 25 | 26 | it('is false for non-string and non-regex patterns', () => { 27 | expect(endsWith(baseString, false)).toBe(false); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/escapeHTML/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/escapeHTML` 2 | 3 | Takes the input text and converts HTML special characters to their entity equivalents. 4 | 5 | **Installation** 6 | `npm i @plexis/escape-html` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import escapeHTML from '@plexis/escape-html'; 12 | 13 | escapeHTML('ABCD'); // returns 'ABCD' 14 | escapeHtml('<3'); // returns '<3' 15 | escapeHtml('

This is cool

'); // returns '<p>This is cool</p>' 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {escapeHTML} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/escapeHTML/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/escape-html", 3 | "version": "0.0.22", 4 | "description": "Takes the input text and converts HTML special characters to their entity equivalents.", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "jsnext:main": "./src/index.js", 8 | "files": [ 9 | "dist", 10 | "src" 11 | ], 12 | "authors": [ 13 | "Nikhil Vats " 14 | ], 15 | "license": "MIT", 16 | "keywords": [ 17 | "utility", 18 | "string", 19 | "parse", 20 | "escapeHTML" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "publishConfig": { 27 | "access": "public" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/escapeHTML/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Takes the input text and converts HTML special characters to their entity equivalents. 3 | * @param {String} text 4 | * @example 5 | * escapeHTML('ABCD'); // returns 'ABCD' 6 | * escapeHtml('<3') // returns '<3' 7 | * escapeHtml('

This is cool

') // returns '<p>This is cool</p>' 8 | */ 9 | const escapeHTML = text => { 10 | var map = { 11 | '&': '&', 12 | '<': '<', 13 | '>': '>', 14 | '"': '"', 15 | "'": ''' 16 | }; 17 | 18 | return text.replace(/[&<>"']/g, function(m) { 19 | return map[m]; 20 | }); 21 | }; 22 | 23 | export default escapeHTML; 24 | -------------------------------------------------------------------------------- /packages/escapeHTML/test/index.js: -------------------------------------------------------------------------------- 1 | import escapeHTML from '../src'; 2 | 3 | it('converts HTML special characters in a string to entity equivalents', () => { 4 | expect(escapeHTML('ABCD')).toBe('ABCD'); 5 | expect(escapeHTML('<3')).toBe('<3'); 6 | expect(escapeHTML('

This is cool

')).toBe('<p>This is cool</p>'); 7 | expect(escapeHTML('
"Rise" & \'Shine\'
')).toBe( 8 | '<div>"Rise" & 'Shine'</div>' 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/head/README.md: -------------------------------------------------------------------------------- 1 | ## `head` 2 | 3 | Extracts the first length characters from the input text. 4 | 5 | `npm i @plexis/head` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import head from '@plexis/head'; 11 | 12 | head(); // => '' 13 | head('Hello'); // => 'H' 14 | head('Hello', 2); // => 'He' 15 | head('Hello', 100); // => 'Hello' 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {head} from 'plexis'; 22 | import {first} from 'plexis'; 23 | import {popFirst} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/head/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/head", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/head/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Extracts the first length characters from the input text. 3 | * @param {String} text 4 | * @param {Number} length 5 | * @example 6 | * head(); // => '' 7 | * head('Hello'); // => 'H' 8 | * head('Hello', 2); // => 'He' 9 | * head('Hello', 100); // => 'Hello' 10 | */ 11 | const head = (text = '', length = 1) => { 12 | if (typeof text !== 'string') { 13 | throw new Error('Input text must be of type string'); 14 | } 15 | 16 | if (isNaN(length) || typeof length !== 'number') { 17 | throw new Error('Length characters must be of type number'); 18 | } 19 | 20 | return text.substr(0, length); 21 | }; 22 | 23 | export default head; 24 | -------------------------------------------------------------------------------- /packages/head/test/index.js: -------------------------------------------------------------------------------- 1 | import head from '../src'; 2 | 3 | describe('returns the first length characters from the input text', () => { 4 | const cases = [{text: 'John'}, {text: 'Doe', length: 2}, {text: 'Hello', length: 100}]; 5 | const expected = ['J', 'Do', 'Hello']; 6 | 7 | cases.forEach(({text, length}, i) => { 8 | test(`head(${text},${length})`, () => { 9 | expect(head(text, length)).toBe(expected[i]); 10 | }); 11 | }); 12 | }); 13 | 14 | test('returns empty string if there is no input text provided', () => { 15 | expect(head()).toBe(''); 16 | }); 17 | 18 | describe('throws error if text is invalid', () => { 19 | const invalids = [null, NaN, {key: 'value'}, ['invalid'], 55]; 20 | 21 | invalids.forEach(invalid => { 22 | test(`head(${invalid})`, () => { 23 | expect(() => { 24 | head(invalid); 25 | }).toThrow(); 26 | }); 27 | }); 28 | }); 29 | 30 | describe('throws error if length is invalid', () => { 31 | const invalids = [NaN, null, '55', {key: 'value'}, ['invalid']]; 32 | 33 | invalids.forEach(invalid => { 34 | test(`head('Hello',${invalid})`, () => { 35 | expect(() => { 36 | head('Hello', invalid); 37 | }).toThrow(); 38 | }); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /packages/includes/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/includes` 2 | 3 | Checks if the search is part of the input string in the given position 4 | 5 | **Installation** 6 | `npm i @plexis/includes` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import includes from '@plexis/includes'; 12 | 13 | includes(); // => false 14 | includes(''); // => false 15 | includes('', ''); // => true 16 | includes('Foo', 'Foo'); // => true 17 | includes('Foo', 'Foo'); // => true 18 | includes('Foo', 'Foo', 2); // => false 19 | includes('Foo', 'oo'); // => true 20 | includes('Foo', 'Oo'); // => false 21 | ``` 22 | 23 | **Aliases** 24 | 25 | ```javascript 26 | import includes from '@plexis/includes'; 27 | import {includes, has} from 'plexis'; 28 | ``` 29 | -------------------------------------------------------------------------------- /packages/includes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/includes", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "author": "edKim ", 8 | "license": "MIT", 9 | "files": [ 10 | "dist", 11 | "src" 12 | ], 13 | "keywords": [ 14 | "utility", 15 | "string", 16 | "parse", 17 | "format", 18 | "validate" 19 | ], 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/plexis-js/plexis.git" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/includes/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks if the search is part of the input string in the given position 3 | * @params {string} [inputString] input string 4 | * @params {string) [searchString] search string 5 | * @params {number} [position] - check at given position 6 | * @return {boolean} Whether string2 is part of string1 7 | * @example 8 | * includes('Foo', 'oo') // returns true 9 | * includes('Foo', 'Foo', 2) // returns false 10 | */ 11 | 12 | const includes = (inputString, searchString, position = 0) => 13 | !!( 14 | typeof inputString === 'string' && 15 | typeof searchString === 'string' && 16 | RegExp(searchString, 'g').test(inputString.substring(position)) 17 | ); 18 | 19 | export default includes; 20 | -------------------------------------------------------------------------------- /packages/includes/test/includes.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import includes from '../src'; 4 | 5 | describe('@plexis/isNumeric', () => { 6 | it('no first or second string parameter given', () => { 7 | expect(includes()).toBe(false); 8 | }); 9 | 10 | it('no second parameter given', () => { 11 | expect(includes('')).toBe(false); 12 | }); 13 | 14 | it('empty string given for first and second string parameters', () => { 15 | expect(includes('', '')).toBe(true); 16 | }); 17 | 18 | it('Equal first string and second string parameters', () => { 19 | expect(includes('Foo', 'Foo')).toBe(true); 20 | }); 21 | 22 | it('Equal first string and second string with starting position of 2', () => { 23 | expect(includes('Foo', 'Foo', 2)).toBe(false); 24 | }); 25 | 26 | it('Second parameter as substring of first parameter', () => { 27 | expect(includes('Foo', 'oo')).toBe(true); 28 | }); 29 | 30 | it('Second parameter as substring of first parameter, but substring has different casing', () => { 31 | expect(includes('Foo', 'Oo')).toBe(false); 32 | }); 33 | 34 | it('Second parameter as non string value', () => { 35 | expect(includes('Foo', false)).toBe(false); 36 | }); 37 | 38 | it('First parameter as non string value', () => { 39 | expect(includes(null, 'Foo')).toBe(false); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/insert/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/insert` 2 | 3 | Inserts into the input text a string at specified position. 4 | 5 | `npm i @plexis/insert` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import insert from '@plexis/insert'; 11 | 12 | insert(); // returns '' 13 | insert('foo ba'); // returns 'foo ba' 14 | insert('foo ba', 'r'); // returns 'foo bar' 15 | insert('foo ba', 'r', 1); // returns 'foo bar' 16 | insert('foo ba', 'r', 100); // returns 'foo bar' 17 | insert('foo ba', 'r', -100); // returns 'foo bar' 18 | insert('oo bar', 'r', 0); // returns 'foo bar' 19 | ``` 20 | 21 | **Aliases** 22 | 23 | ```javascript 24 | import insert from '@plexis/insert'; 25 | import {insert} from 'plexis'; 26 | ``` 27 | -------------------------------------------------------------------------------- /packages/insert/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/insert", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "description": "Inserts into the input text a string at specified position.", 8 | "keywords": [ 9 | "utility", 10 | "string", 11 | "format" 12 | ], 13 | "author": "Angel Gonzalez ", 14 | "homepage": "https://github.com/plexis-js/plexis#readme", 15 | "license": "MIT", 16 | "files": [ 17 | "lib" 18 | ], 19 | "publishConfig": { 20 | "access": "public" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/plexis-js/plexis.git" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/plexis-js/plexis/issues" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/insert/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Inserts into the input text a string at specified position 3 | * @param {String} text 4 | * @param {String} textToInsert 5 | * @param {Number} insertPosition 6 | * 7 | * @example 8 | * insert('foo ba'); // returns 'foo ba' 9 | * insert('foo ba', "r"); // returns 'foo bar' 10 | * insert('foo ba', "r", 6); // returns 'foo bar' 11 | * insert('foo ba', "r", 100); // returns 'foo bar' 12 | * insert('foo ba', "r", -100); // returns 'foo bar' 13 | * insert('oo bar', "f", 0); // returns 'foo bar' 14 | */ 15 | 16 | const insert = (text = '', textToInsert = '', insertPosition = text.length) => { 17 | if (insertPosition < 0 || insertPosition > text.length || textToInsert === '') { 18 | return text + textToInsert; 19 | } 20 | return text.slice(0, insertPosition) + textToInsert + text.slice(insertPosition); 21 | }; 22 | 23 | export default insert; 24 | -------------------------------------------------------------------------------- /packages/insert/test/insert.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import insert from '../src'; 4 | describe('@plexis/to-human', () => { 5 | it('returns an empty string', () => { 6 | expect(insert()).toBe(''); 7 | expect(insert('')).toBe(''); 8 | expect(insert('', '')).toBe(''); 9 | expect(insert('', '', 0)).toBe(''); 10 | expect(insert('', '', 100)).toBe(''); 11 | }); 12 | 13 | it('returns the same input', () => { 14 | expect(insert('foo bar')).toBe('foo bar'); 15 | expect(insert('foo bar', '')).toBe('foo bar'); 16 | expect(insert('foo bar', '', 100)).toBe('foo bar'); 17 | }); 18 | 19 | it('return the input with inserted text at the end', () => { 20 | expect(insert('foo ba', 'r', 6)).toBe('foo bar'); 21 | expect(insert('foo ba', 'r', 100)).toBe('foo bar'); 22 | expect(insert('foo ba', 'r', -100)).toBe('foo bar'); 23 | }); 24 | 25 | it('return the input with inserted text at n position', () => { 26 | expect(insert('foo br', 'a', 5)).toBe('foo bar'); 27 | expect(insert('foo ba', 'r', 100)).toBe('foo bar'); 28 | expect(insert('foo ba', 'r', -100)).toBe('foo bar'); 29 | expect(insert('oo bar', 'f', 0)).toBe('foo bar'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /packages/isAlpha/.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.test.js 3 | .prettierrc 4 | .github 5 | .template 6 | .package-template 7 | .nyc_output 8 | .circleci 9 | .commitlintrc.js 10 | coverage 11 | coverage.lcov 12 | docs 13 | babel.config.js 14 | test 15 | CONTRIBUTING.md 16 | CODE_OF_CONDUCT.md 17 | LICENCE -------------------------------------------------------------------------------- /packages/isAlpha/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/isAlpha` 2 | 3 | Check whether a string contains only alpha characters. 4 | 5 | **Installation** 6 | `npm i @plexis/is-alpha` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import isAlpha from '@plexis/is-alpha'; 12 | 13 | isAlpha('Foo Bar'); // returns false 14 | isAlpha('FooBar'); // returns true 15 | isAlpha('f00b4r'); // returns false 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import {isAlpha} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/isAlpha/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-alpha", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "authors": [ 8 | "Rob Fairclough https://github.com/robfairclough" 9 | ], 10 | "license": "MIT", 11 | "keywords": [ 12 | "utility", 13 | "string", 14 | "parse", 15 | "format", 16 | "validate", 17 | "alpha", 18 | "ascii" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/plexis-js/plexis.git" 23 | }, 24 | "publishConfig": { 25 | "access": "public" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/isAlpha/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether a given string contains only alpha characters 3 | * @param {string} text 4 | * @example 5 | * isAlpha('Hello') // returns true 6 | * isAlpha('Hello, there!') // returns false 7 | * isAlpha('123') // returns false 8 | * isAlpha('oneTwoThree') // returns true 9 | */ 10 | 11 | const isAlpha = text => { 12 | if (!text || typeof text !== 'string') return false; 13 | if (/[^a-z]/gi.test(text)) return false; 14 | return true; 15 | }; 16 | 17 | export default isAlpha; 18 | -------------------------------------------------------------------------------- /packages/isAlpha/test/index.js: -------------------------------------------------------------------------------- 1 | import isAlpha from '../src'; 2 | 3 | describe('isAlpha function', () => { 4 | it('should return false for an empty string', () => { 5 | expect(isAlpha('')).toBe(false); 6 | }); 7 | 8 | it('should return false for a numeric input regardless of type', () => { 9 | expect(isAlpha(1)).toBe(false); 10 | expect(isAlpha('1')).toBe(false); 11 | expect(isAlpha({1: '1'})).toBe(false); 12 | }); 13 | 14 | it('should return true for a single word', () => { 15 | expect(isAlpha('word')).toBe(true); 16 | }); 17 | 18 | it('should return false for a string with spaces', () => { 19 | expect(isAlpha('Hello, there')).toBe(false); 20 | }); 21 | 22 | it('should return false for a string with punctuation', () => { 23 | expect(isAlpha('hey!')).toBe(false); 24 | }); 25 | 26 | it('should return true for an all-alpha string with mixed case', () => { 27 | expect(isAlpha('wHaTtHeTeSt')).toBe(true); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/isAlphaNumeric/.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.test.js 3 | .prettierrc 4 | .github 5 | .template 6 | .package-template 7 | .nyc_output 8 | .circleci 9 | .commitlintrc.js 10 | coverage 11 | coverage.lcov 12 | docs 13 | babel.config.js 14 | test 15 | CONTRIBUTING.md 16 | CODE_OF_CONDUCT.md 17 | LICENCE -------------------------------------------------------------------------------- /packages/isAlphaNumeric/README.md: -------------------------------------------------------------------------------- 1 | ## `isAlphaNumeric` 2 | 3 | Checks whether the input is a string containing only alphanumeric characters. 4 | 5 | `npm i @plexis/is-alphanumeric` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import isAlphaNumeric from '@plexis/is-alphanumeric'; 11 | 12 | isAlphaNumeric('foo123BAR'); // returns true 13 | isAlphaNumeric('1.0'); // returns false 14 | isAlphaNumeric('bar!'); // returns false 15 | isAlphaNumeric(''); // returns false 16 | ``` 17 | 18 | **Aliases** 19 | 20 | ```javascript 21 | import isAlphaNumeric from '@plexis/is-alphanumeric'; 22 | import {isAlphaNumeric, isAlphanumeric, isAlphaDigit} from 'plexis'; 23 | ``` 24 | -------------------------------------------------------------------------------- /packages/isAlphaNumeric/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-alphanumeric", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "license": "MIT", 8 | "keywords": [ 9 | "utility", 10 | "string", 11 | "parse", 12 | "format", 13 | "validate" 14 | ], 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/plexis-js/plexis.git" 18 | }, 19 | "publishConfig": { 20 | "access": "public" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/isAlphaNumeric/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the input is a string containing only alphanumeric characters 3 | * @param {String} text 4 | * @example 5 | * isAlphaNumeric('fooBAR') // returns true 6 | * isAlphaNumeric('123') // returns true 7 | * isAlphaNumeric('foo123BAR') // returns true 8 | * isAlphaNumeric('1.0') // returns false 9 | * isAlphaNumeric('bar!') // returns false 10 | * isAlphaNumeric('') // returns false 11 | */ 12 | const isAlphaNumeric = text => (typeof text === 'string' ? /^[A-Za-z0-9]+$/.test(text) : false); 13 | 14 | export default isAlphaNumeric; 15 | -------------------------------------------------------------------------------- /packages/isAlphaNumeric/test/index.js: -------------------------------------------------------------------------------- 1 | import isAlphaNumeric from '../src'; 2 | 3 | it('should return true for a string of alphabetical characters (upper- and lower-case)', () => { 4 | expect(isAlphaNumeric('fooBAR')).toBe(true); 5 | }); 6 | 7 | it('should return true for a string of numeric characters', () => { 8 | expect(isAlphaNumeric('123')).toBe(true); 9 | }); 10 | 11 | it('should return true for a string of alphabetical and numeric characters', () => { 12 | expect(isAlphaNumeric('fooBAR123')).toBe(true); 13 | }); 14 | 15 | it('should return false for strings with non-numeric characters', () => { 16 | expect(isAlphaNumeric('!')).toBe(false); 17 | expect(isAlphaNumeric('@')).toBe(false); 18 | expect(isAlphaNumeric('.')).toBe(false); 19 | expect(isAlphaNumeric(' ')).toBe(false); 20 | expect(isAlphaNumeric('-')).toBe(false); 21 | expect(isAlphaNumeric('_')).toBe(false); 22 | expect(isAlphaNumeric('=')).toBe(false); 23 | expect(isAlphaNumeric('+')).toBe(false); 24 | expect(isAlphaNumeric('(')).toBe(false); 25 | expect(isAlphaNumeric('^')).toBe(false); 26 | expect(isAlphaNumeric('ä')).toBe(false); 27 | }); 28 | 29 | it('should return false for an empty string', () => { 30 | expect(isAlphaNumeric('')).toBe(false); 31 | }); 32 | 33 | it('should return false for inputs that are not strings', () => { 34 | expect(isAlphaNumeric(0)).toBe(false); 35 | expect(isAlphaNumeric(1.5)).toBe(false); 36 | expect(isAlphaNumeric(true)).toBe(false); 37 | expect(isAlphaNumeric(null)).toBe(false); 38 | expect(isAlphaNumeric(undefined)).toBe(false); 39 | expect(isAlphaNumeric({foo: 'bar'})).toBe(false); 40 | expect(isAlphaNumeric(['foo', 'bar'])).toBe(false); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/isEmpty/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/is-empty` 2 | 3 | Checks whether the input text is empty. 4 | 5 | **Installation** 6 | `npm i @plexis/to-lower` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import isEmpty from '@plexis/isEmpty'; 12 | 13 | isEmpty(''); // returns true 14 | isEmpty(' '); // returns true 15 | isEmpty(' b '); // returns false 16 | isEmpty('Hello'); //returns false 17 | ``` 18 | 19 | **Aliases** 20 | 21 | ```javascript 22 | import isEmpty from '@plexis/is-empty'; 23 | import {isEmpty} from 'plexis'; 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/isEmpty/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-empty", 3 | "version": "0.0.22", 4 | "description": "Checks whether the input text is empty.", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "jsnext:main": "./src/index.js", 8 | "author": "eElec ", 9 | "files": [ 10 | "dist", 11 | "src" 12 | ], 13 | "license": "MIT", 14 | "keywords": [ 15 | "utility", 16 | "string", 17 | "parse", 18 | "format", 19 | "validate" 20 | ], 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/plexis-js/plexis.git" 24 | }, 25 | "publishConfig": { 26 | "access": "public" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/isEmpty/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the input text is empty 3 | * @param {String} text 4 | * @example 5 | * isEmpty('') // returns true 6 | * isEmpty(' ') // returns true 7 | * isEmpty(' b ') // returns false 8 | */ 9 | const isEmpty = text => /^\s*$/.test(text); 10 | 11 | export default isEmpty; 12 | -------------------------------------------------------------------------------- /packages/isEmpty/test/index.js: -------------------------------------------------------------------------------- 1 | import isEmpty from '../src/'; 2 | 3 | it('check empty string', () => { 4 | expect(isEmpty('')).toBe(true); 5 | }); 6 | 7 | it('check string with spaces', () => { 8 | expect(isEmpty(' ')).toBe(true); 9 | }); 10 | 11 | it('check string ith spaces and character', () => { 12 | expect(isEmpty(' b ')).toBe(false); 13 | }); 14 | 15 | it('check string with characters', () => { 16 | expect(isEmpty('Hello')).toBe(false); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/isLowerCase/README.md: -------------------------------------------------------------------------------- 1 | ## `isLowerCase` 2 | 3 | Checks whether the input is a string containing only lowercase characters 4 | 5 | `npm i @plexis/is-lowercase` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import isLowerCase from '@plexis/is-lowercase'; 11 | 12 | isLowerCase('foo'); // returns true 13 | isLowerCase('Foo'); // returns false 14 | isLowerCase('BAR'); // returns false 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import {isLowerCase} from 'plexis'; 21 | import {isLower} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/isLowerCase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-lowercase", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/isLowerCase/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the input is a string containing only lowercase characters 3 | * @param {String} text 4 | * @example 5 | * isLowerCase('foo') // returns true 6 | * isLowerCase('Foo') // returns false 7 | * isLowerCase('BAR') // returns false 8 | */ 9 | const isLowerCase = text => text === text.toLowerCase(); 10 | 11 | export default isLowerCase; 12 | -------------------------------------------------------------------------------- /packages/isLowerCase/test/index.js: -------------------------------------------------------------------------------- 1 | import isLowerCase from '../src'; 2 | 3 | it('check a uppercase string', () => { 4 | expect(isLowerCase('HELLO')).toBe(false); 5 | }); 6 | 7 | it('check a lowercase with spaces string', () => { 8 | expect(isLowerCase('foo bar')).toBe(true); 9 | }); 10 | 11 | it('check a lowercase string', () => { 12 | expect(isLowerCase('hello')).toBe(true); 13 | }); 14 | 15 | it('check a lowercase string with an uppercase char in the middle', () => { 16 | expect(isLowerCase('hello Foo bar')).toBe(false); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/isNumeric/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/isNumeric` 2 | 3 | Validates if argument is valid numeric value. 4 | 5 | **Installation** 6 | `npm i @plexis/is-numeric` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import isNumeric from '@plexis/is-numeric'; 12 | 13 | isNumeric('1000'); 14 | // => true 15 | 16 | isNumeric('Infinity'); 17 | // => true 18 | 19 | isNumeric('-100.4'); 20 | // => true 21 | 22 | isNumeric('1E+2'); 23 | // => true 24 | 25 | isNumeric('0xFF'); 26 | // => true 27 | 28 | isNumeric('-'); 29 | // => false 30 | 31 | isNumeric('one'); 32 | // => false 33 | ``` 34 | 35 | **Aliases** 36 | 37 | ```javascript 38 | import {isNum} from 'plexis'; 39 | import {isNumeric} from 'plexis'; 40 | ``` 41 | -------------------------------------------------------------------------------- /packages/isNumeric/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-numeric", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "author": "edKim ", 8 | "license": "MIT", 9 | "files": [ 10 | "dist", 11 | "src" 12 | ], 13 | "keywords": [ 14 | "utility", 15 | "string", 16 | "parse", 17 | "format", 18 | "validate" 19 | ], 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/plexis-js/plexis.git" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/isNumeric/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the argument given is a number 3 | * @param {Any} value to validate 4 | * @return {boolean} Whether the argument passed was a number or not 5 | * @example 6 | * isNumeric('1000') // returns true 7 | * isNumeric('Foo') // returns false 8 | */ 9 | 10 | const isNumeric = value => !isNaN(Number(value)); 11 | 12 | export default isNumeric; 13 | -------------------------------------------------------------------------------- /packages/isNumeric/test/isNumeric.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import isNumeric from '../src'; 4 | 5 | describe('@plexis/isNumeric', () => { 6 | it('check a valid numeric value `1000` ', () => { 7 | expect(isNumeric('1000')).toBe(true); 8 | }); 9 | 10 | it('test if Infinity is a valid number', () => { 11 | expect(isNumeric('Infinity')).toBe(true); 12 | }); 13 | 14 | it('test against a negative numeric value', () => { 15 | expect(isNumeric('-100.4')).toBe(true); 16 | }); 17 | 18 | it('test against a number in exponent shorthand', () => { 19 | expect(isNumeric('1E+2')).toBe(true); 20 | }); 21 | 22 | it('test against a hex number', () => { 23 | expect(isNumeric('0xFF')).toBe(true); 24 | }); 25 | 26 | it('test against a dash', () => { 27 | expect(isNumeric('-')).toBe(false); 28 | }); 29 | 30 | it('test against a string representation of a number', () => { 31 | expect(isNumeric('one')).toBe(false); 32 | }); 33 | 34 | it('test against a number', () => { 35 | expect(isNumeric(100)).toBe(true); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/isString/README.md: -------------------------------------------------------------------------------- 1 | ## `isString` 2 | 3 | Checks whether the input is a string primitive type. 4 | 5 | `npm i @plexis/is-string` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import isString from '@plexis/is-string'; 11 | 12 | isString('Foo'); // returns 'true' 13 | isString(1); // returns 'false' 14 | isString(null); // returns 'false' 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import {isString} from 'plexis'; 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/isString/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-string", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/isString/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the input is a string primitive type. 3 | * @param {String} param 4 | * @returns {Boolean} 5 | * @example 6 | * isString('Foo') // returns 'true' 7 | * isString(1) // returns 'false' 8 | * isString(null) // returns 'false' 9 | */ 10 | const isString = param => typeof param === 'string'; 11 | 12 | export default isString; 13 | -------------------------------------------------------------------------------- /packages/isString/test/index.js: -------------------------------------------------------------------------------- 1 | import isString from '../src'; 2 | 3 | it('returns false for non-string types', () => { 4 | const nonStrings = [5, false, true, null, undefined, {}, [1, 2], []]; 5 | 6 | nonStrings.forEach(param => { 7 | expect(isString(param)).toBe(false); 8 | }); 9 | }); 10 | 11 | it('returns true for string type', () => { 12 | const strings = [ 13 | 'Foo', 14 | '', 15 | false.toString(), 16 | (1).toString(), 17 | {foo: 'bar'}.toString(), 18 | [1, 2, 3, 4].toString() 19 | ]; 20 | 21 | strings.forEach(param => { 22 | expect(isString(param)).toBe(true); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /packages/isUpperCase/README.md: -------------------------------------------------------------------------------- 1 | ## `isUpperCase` 2 | 3 | Checks whether the input is a string containing only uppercase characters 4 | 5 | `npm i @plexis/is-uppercase` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import isUpperCase from '@plexis/is-uppercase'; 11 | 12 | isUpperCase️('b'); // returns false 13 | isUpperCase️('B'); // returns true 14 | isUpperCase️('BCD'); // returns true 15 | ``` 16 | 17 | **Aliases** 18 | 19 | ```javascript 20 | import {isUpperCase} from 'plexis'; 21 | import {isUpper} from 'plexis'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/isUpperCase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/is-uppercase", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "license": "MIT", 12 | "keywords": [ 13 | "utility", 14 | "string", 15 | "parse", 16 | "format", 17 | "validate" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/isUpperCase/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the input is a string containing only uppercase characters 3 | * @param {String} text 4 | * @example 5 | * isUpperCase️('b') // returns false 6 | * isUpperCase️('B') // returns true 7 | * isUpperCase️('BCD') // returns true 8 | */ 9 | const isUpperCase️ = text => text === text.toUpperCase(); 10 | 11 | export default isUpperCase️; 12 | -------------------------------------------------------------------------------- /packages/isUpperCase/test/index.js: -------------------------------------------------------------------------------- 1 | import isUpperCase from '../src'; 2 | 3 | it('check a uppercase string', () => { 4 | expect(isUpperCase('HELLO')).toBe(true); 5 | }); 6 | 7 | it('check a uppercase with spaces string', () => { 8 | expect(isUpperCase('HELLO FOO BAR')).toBe(true); 9 | }); 10 | 11 | it('check a lowercase string', () => { 12 | expect(isUpperCase('hello')).toBe(false); 13 | }); 14 | 15 | it('check a uppercase string with an lowercase char in the middle', () => { 16 | expect(isUpperCase('HELLO FOo BAR')).toBe(false); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/plexis/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | ### Plexis: Lo-fi, powerful, community-driven string manipulation library. 4 | 5 |
6 | 7 | Learn more about [Plexis](/README.md) or take a look at the [API](/docs/pages/api.md). 8 | -------------------------------------------------------------------------------- /packages/plexis/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "plexis", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Theodore Vorillas (https://vorillaz.com)" 13 | ], 14 | "license": "MIT", 15 | "dependencies": { 16 | "@plexis/compare": "^0.0.22", 17 | "@plexis/compose": "^0.0.22", 18 | "@plexis/count": "^0.0.22", 19 | "@plexis/distance": "^0.0.22", 20 | "@plexis/ends-with": "^0.0.22", 21 | "@plexis/escape-html": "^0.0.22", 22 | "@plexis/head": "^0.0.22", 23 | "@plexis/includes": "^0.0.22", 24 | "@plexis/insert": "^0.0.22", 25 | "@plexis/is-alpha": "^0.0.22", 26 | "@plexis/is-alphanumeric": "^0.0.22", 27 | "@plexis/is-lowercase": "^0.0.22", 28 | "@plexis/is-numeric": "^0.0.22", 29 | "@plexis/is-string": "^0.0.22", 30 | "@plexis/is-uppercase": "^0.0.22", 31 | "@plexis/starts-with": "^0.0.22", 32 | "@plexis/tail": "^0.0.22", 33 | "@plexis/to-camel-case": "^0.0.22", 34 | "@plexis/to-capitals": "^0.0.22", 35 | "@plexis/to-chicago": "^0.0.22", 36 | "@plexis/to-chunks": "^0.0.22", 37 | "@plexis/to-human": "^0.0.22", 38 | "@plexis/to-lower": "^0.0.22", 39 | "@plexis/to-pascal-case": "^0.0.22", 40 | "@plexis/to-plural": "^0.0.22", 41 | "@plexis/to-pred": "^0.0.22", 42 | "@plexis/to-snake-case": "^0.0.22", 43 | "@plexis/to-succ": "^0.0.22", 44 | "@plexis/to-swap": "^0.0.22", 45 | "@plexis/to-swap-case": "^0.0.22", 46 | "@plexis/to-title": "^0.0.22", 47 | "@plexis/when": "^0.0.22", 48 | "@plexis/without-diacritics": "^0.0.22", 49 | "@plexis/without-html": "^0.0.22", 50 | "@plexis/without-indent": "^0.0.22", 51 | "@plexis/is-empty": "^0.0.22", 52 | "@plexis/count-words": "^0.0.22", 53 | "@plexis/to-ellipsis": "^0.0.22" 54 | }, 55 | "keywords": [ 56 | "utility", 57 | "string", 58 | "parse", 59 | "format", 60 | "validate" 61 | ], 62 | "repository": { 63 | "type": "git", 64 | "url": "git+https://github.com/plexis-js/plexis.git" 65 | }, 66 | "publishConfig": { 67 | "access": "public" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /packages/plexis/src/index.js: -------------------------------------------------------------------------------- 1 | export { 2 | default as compare, 3 | default as compareLikeHuman, 4 | default as naturalCompare 5 | } from '@plexis/compare'; 6 | export {default as compose, default as _do} from '@plexis/compose'; 7 | export {default as count} from '@plexis/count'; 8 | export { 9 | default as calcLevenshtein, 10 | default as distance, 11 | default as levenshtein 12 | } from '@plexis/distance'; 13 | export {default as endsWith} from '@plexis/ends-with'; 14 | export {default as escapeHTML} from '@plexis/escape-html'; 15 | export {default as head, default as first, default as popFirst} from '@plexis/head'; 16 | export {default as insert} from '@plexis/insert'; 17 | export {default as isAlpha} from '@plexis/is-alpha'; 18 | export {default as isLower, default as isLowerCase} from '@plexis/is-lowercase'; 19 | export {default as isNum, default as isNumeric} from '@plexis/is-numeric'; 20 | export {default as includes, default as has} from '@plexis/includes'; 21 | export {default as isString} from '@plexis/is-string'; 22 | export {default as isUpper, default as isUpperCase} from '@plexis/is-uppercase'; 23 | export {default as startsWith} from '@plexis/starts-with'; 24 | export { 25 | default as camelCase, 26 | default as camelize, 27 | default as toCamelCase 28 | } from '@plexis/to-camel-case'; 29 | export { 30 | default as toCapitals, 31 | default as toFirstCapital, 32 | default as capitalize 33 | } from '@plexis/to-capitals'; 34 | export { 35 | default as toChicagoManualStyle, 36 | default as toChicagoStyle, 37 | default as toChicagoTitle, 38 | default as toTurabian 39 | } from '@plexis/to-chicago'; 40 | export {default as toSwapCase, default as swapCase} from '@plexis/to-swap-case'; 41 | export {default as toChunks} from '@plexis/to-chunks'; 42 | export { 43 | default as decapitalize, 44 | default as toFirstLower, 45 | default as toLower 46 | } from '@plexis/to-lower'; 47 | export {default as classify, default as toPascalCase} from '@plexis/to-pascal-case'; 48 | export {default as pluralize, default as toPlural} from '@plexis/to-plural'; 49 | export {default as toPred, default as toPredecessor} from '@plexis/to-pred'; 50 | export {default as snakeCase, default as toSnakeCase} from '@plexis/to-snake-case'; 51 | export {default as toSucc, default as toSuccessor} from '@plexis/to-succ'; 52 | export {default as titleize, default as toTitle} from '@plexis/to-title'; 53 | export {default as _when} from '@plexis/when'; 54 | export {default as humanize, default as toHuman} from '@plexis/to-human'; 55 | export { 56 | default as cleanDiacritics, 57 | default as removeDiacritics, 58 | default as withoutDiacritics 59 | } from '@plexis/without-diacritics'; 60 | export { 61 | default as dedent, 62 | default as removeIndent, 63 | default as withoutIndent 64 | } from '@plexis/without-indent'; 65 | export { 66 | default as isAlphaNumeric, 67 | default as isAlphanumeric, 68 | default as isAlphaDigit 69 | } from '@plexis/is-alphanumeric'; 70 | export {default as withoutHTML, default as removeHTML} from '@plexis/without-html'; 71 | export {default as isEmpty} from '@plexis/is-empty'; 72 | export {default as tail, default as rest, default as last, default as pop} from '@plexis/tail'; 73 | export {default as toSwap, default as swap} from '@plexis/to-swap'; 74 | export {default as countWords} from '@plexis/count-words'; 75 | export {default as toEllipsis, default as truncate, default as fit} from '@plexis/to-ellipsis'; 76 | -------------------------------------------------------------------------------- /packages/plexis/test/__snapshots__/index.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`allows using all the available utilities 1`] = ` 4 | Array [ 5 | "__esModule", 6 | "compare", 7 | "compareLikeHuman", 8 | "naturalCompare", 9 | "compose", 10 | "_do", 11 | "count", 12 | "calcLevenshtein", 13 | "distance", 14 | "levenshtein", 15 | "endsWith", 16 | "escapeHTML", 17 | "head", 18 | "first", 19 | "popFirst", 20 | "insert", 21 | "isAlpha", 22 | "isLower", 23 | "isLowerCase", 24 | "isNum", 25 | "isNumeric", 26 | "includes", 27 | "has", 28 | "isString", 29 | "isUpper", 30 | "isUpperCase", 31 | "startsWith", 32 | "camelCase", 33 | "camelize", 34 | "toCamelCase", 35 | "toCapitals", 36 | "toFirstCapital", 37 | "capitalize", 38 | "toChicagoManualStyle", 39 | "toChicagoStyle", 40 | "toChicagoTitle", 41 | "toTurabian", 42 | "toSwapCase", 43 | "swapCase", 44 | "toChunks", 45 | "decapitalize", 46 | "toFirstLower", 47 | "toLower", 48 | "classify", 49 | "toPascalCase", 50 | "pluralize", 51 | "toPlural", 52 | "toPred", 53 | "toPredecessor", 54 | "snakeCase", 55 | "toSnakeCase", 56 | "toSucc", 57 | "toSuccessor", 58 | "titleize", 59 | "toTitle", 60 | "_when", 61 | "humanize", 62 | "toHuman", 63 | "cleanDiacritics", 64 | "removeDiacritics", 65 | "withoutDiacritics", 66 | "dedent", 67 | "removeIndent", 68 | "withoutIndent", 69 | "isAlphaNumeric", 70 | "isAlphanumeric", 71 | "isAlphaDigit", 72 | "withoutHTML", 73 | "removeHTML", 74 | "isEmpty", 75 | "tail", 76 | "rest", 77 | "last", 78 | "pop", 79 | "toSwap", 80 | "swap", 81 | "countWords", 82 | "toEllipsis", 83 | "truncate", 84 | "fit", 85 | ] 86 | `; 87 | -------------------------------------------------------------------------------- /packages/plexis/test/index.js: -------------------------------------------------------------------------------- 1 | import * as plexis from '../src/index'; 2 | 3 | it('allows using all the available utilities', () => { 4 | expect(Object.keys(plexis)).toMatchSnapshot(); 5 | }); 6 | -------------------------------------------------------------------------------- /packages/repeat/README.md: -------------------------------------------------------------------------------- 1 | # `@plexis/repeat` 2 | 3 | Repeats the input text number of times. 4 | 5 | **Installation** 6 | `npm i @plexis/repeat` 7 | 8 | **Usage** 9 | 10 | ```javascript 11 | import repeat from '@plexis/repeat'; 12 | 13 | repeat('ABCD'); 14 | // => true 15 | 16 | repeat('Apollo11', 2); 17 | // => 'Apollo11Apollo11' 18 | 19 | repeat('x', 2); 20 | // => 'xx' 21 | 22 | repeat('x', 2, '+'); 23 | // => 'x+x' 24 | 25 | repeat('xx', 2, '_'); 26 | // => 'xx_xx' 27 | ``` 28 | 29 | **Aliases** 30 | 31 | ```javascript 32 | import repeat from '@plexis/repeat'; 33 | import {repeat, multiply} from 'plexis'; 34 | ``` 35 | -------------------------------------------------------------------------------- /packages/repeat/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/repeat", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "authors": [ 12 | "Lazar Vasic " 13 | ], 14 | "license": "MIT", 15 | "keywords": [ 16 | "utility", 17 | "function" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/plexis-js/plexis.git" 22 | }, 23 | "publishConfig": { 24 | "access": "public" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/repeat/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Repeats the input text number of times. 3 | * @param {String} [text] The input text. 4 | * @returns {Integer} times How many times shall we repeat the text, default to 1 5 | * @param {String} glue The glue for the output, default to '' 6 | * @returns {String} The repeated string; 7 | */ 8 | 9 | const repeat = (text, times = 1, glue = '') => { 10 | let result = `${text}${glue}`.repeat(times); 11 | if (glue) { 12 | return result.slice(0, result.length - 1); 13 | } 14 | return result; 15 | }; 16 | 17 | export default repeat; 18 | -------------------------------------------------------------------------------- /packages/repeat/test/index.js: -------------------------------------------------------------------------------- 1 | import repeat from '../src'; 2 | 3 | it('repeat text with repeat param and default glue', () => { 4 | const result = repeat('ABCD'); 5 | expect(result).toBe('ABCD'); 6 | }); 7 | 8 | it('repeat text with repeat param and default glue', () => { 9 | const result = repeat('Apollo11', 2); 10 | expect(result).toBe('Apollo11Apollo11'); 11 | }); 12 | 13 | it('repeat text with repeat param and glue', () => { 14 | const result = repeat('x', 2, '+'); 15 | expect(result).toBe('x+x'); 16 | }); 17 | 18 | it('repeat text with repeat param and glue', () => { 19 | const result = repeat('xx', 2, '_'); 20 | expect(result).toBe('xx_xx'); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/startsWith/README.md: -------------------------------------------------------------------------------- 1 | ## `@plexis/startsWith` 2 | 3 | Checks whether the input text starts with the given pattern. 4 | 5 | `npm i @plexis/starts-with` 6 | 7 | **Usage** 8 | 9 | ```javascript 10 | import startsWith from '@plexis/starts-with'; 11 | 12 | startsWith('This is me', 'This is'); // returns true 13 | startsWith('This is me', 'This is', 1); // returns false 14 | startsWith(/[@!#$]/, '@plexis is great!'); // returns true 15 | startsWith(/[A-Z]/, '@plexis is great!'); // returns false 16 | ``` 17 | -------------------------------------------------------------------------------- /packages/startsWith/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@plexis/starts-with", 3 | "version": "0.0.22", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "jsnext:main": "./src/index.js", 7 | "files": [ 8 | "dist", 9 | "src" 10 | ], 11 | "author": "Brandon Skinner ", 12 | "license": "MIT", 13 | "keywords": [ 14 | "utility", 15 | "string", 16 | "parse", 17 | "format", 18 | "validate" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/plexis-js/plexis.git" 23 | }, 24 | "publishConfig": { 25 | "access": "public" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/startsWith/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description Checks whether the input text starts with the given pattern. 3 | * @param {String} text 4 | * @param {String|Regex} pattern 5 | * @param {Number} startingPosition, optional 6 | * @example 7 | * startsWith('This is me', 'This is'); // returns true 8 | * startsWith('This is me', 'This is', 1); // returns false 9 | * startsWith(/[@!#$]/, '@plexis is great!'); // returns true 10 | */ 11 | const startsWith = (text, pattern, startingPosition) => { 12 | try { 13 | if (typeof pattern === 'object') { 14 | return text.slice(startingPosition).search(new RegExp(pattern)) === 0 ? true : false; 15 | } 16 | } catch (e) {} 17 | 18 | return text.slice(startingPosition).indexOf(pattern) === 0 ? true : false; 19 | }; 20 | 21 | export default startsWith; 22 | -------------------------------------------------------------------------------- /packages/startsWith/test/index.js: -------------------------------------------------------------------------------- 1 | import startsWith from '../src'; 2 | 3 | it('Matches single characters', () => { 4 | expect(startsWith('Hello', 'H')).toBe(true); 5 | }); 6 | 7 | it("Doesn't match single characters not at front of string", () => { 8 | expect(startsWith('Hello', 'l')).toBe(false); 9 | }); 10 | 11 | it('Matches single characters with startingPosition set at character index', () => { 12 | expect(startsWith('Help', 'l', 2)).toBe(true); 13 | }); 14 | 15 | it('Matches single word strings', () => { 16 | expect(startsWith('Hello there champ!', 'Hello')).toBe(true); 17 | }); 18 | 19 | it("Doesn't match single word strings not at front of string", () => { 20 | expect(startsWith('Hello there champ!', 'there')).toBe(false); 21 | }); 22 | 23 | it('Matches single word strings with startingPosition set at word index', () => { 24 | expect(startsWith('Hello there champ!', 'there', 6)).toBe(true); 25 | }); 26 | 27 | it('Matches single character regex', () => { 28 | expect(startsWith('@plexis is great!', /[@]/)).toBe(true); 29 | }); 30 | 31 | it("Doesn't match single character regex not at front of string", () => { 32 | expect(startsWith('@plexis is great!', /[!]/)).toBe(false); 33 | }); 34 | 35 | it('Matches single word string', () => { 36 | expect(startsWith('@plexis is great!', /is/, 8)).toBe(true); 37 | }); 38 | 39 | it('Matches complex regex(HTML tag)', () => { 40 | expect(startsWith('
Table Cell