├── .circleci └── config.yml ├── .codeclimate.yml ├── .editorconfig ├── .flowconfig ├── .gitignore ├── .jsdocrc ├── .npmignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build ├── build.js ├── code.js ├── dependecies.js ├── generate.js ├── package.js ├── prefix.js └── readme.js ├── docs ├── append.js.html ├── appendarray.js.html ├── at.js.html ├── base64decode.js.html ├── base64encode.js.html ├── between.js.html ├── bindecode.js.html ├── binencode.js.html ├── chars.js.html ├── collapsewhitespace.js.html ├── compare.js.html ├── contains.js.html ├── containsall.js.html ├── containsany.js.html ├── countsubstr.js.html ├── decdecode.js.html ├── decencode.js.html ├── endswith.js.html ├── ensureleft.js.html ├── ensureright.js.html ├── equal.js.html ├── first.js.html ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.svg │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.svg │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Italic-webfont.svg │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.svg │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ ├── OpenSans-LightItalic-webfont.svg │ ├── OpenSans-LightItalic-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.svg │ ├── OpenSans-Regular-webfont.woff │ ├── OpenSans-Semibold-webfont.eot │ ├── OpenSans-Semibold-webfont.svg │ ├── OpenSans-Semibold-webfont.ttf │ ├── OpenSans-Semibold-webfont.woff │ ├── OpenSans-SemiboldItalic-webfont.eot │ ├── OpenSans-SemiboldItalic-webfont.svg │ ├── OpenSans-SemiboldItalic-webfont.ttf │ └── OpenSans-SemiboldItalic-webfont.woff ├── format.js.html ├── hexdecode.js.html ├── hexencode.js.html ├── htmldecode.js.html ├── htmlencode.js.html ├── index.html ├── indexof.js.html ├── inequal.js.html ├── insert.js.html ├── islowercase.js.html ├── isstring.js.html ├── isuppercase.js.html ├── last.js.html ├── lastindexof.js.html ├── leftpad.js.html ├── lefttrim.js.html ├── module-append.html ├── module-appendArray.html ├── module-at.html ├── module-base64decode.html ├── module-base64encode.html ├── module-between.html ├── module-binDecode.html ├── module-binEncode.html ├── module-chars.html ├── module-collapseWhitespace.html ├── module-compare.html ├── module-contains.html ├── module-containsAll.html ├── module-containsAny.html ├── module-countSubstr.html ├── module-decDecode.html ├── module-decEncode.html ├── module-endsWith.html ├── module-ensureLeft.html ├── module-ensureRight.html ├── module-equal.html ├── module-first.html ├── module-format.html ├── module-hexDecode.html ├── module-hexEncode.html ├── module-htmlDecode.html ├── module-htmlEncode.html ├── module-inequal.html ├── module-insert.html ├── module-isLowerCase.html ├── module-isString.html ├── module-isUpperCase.html ├── module-last.html ├── module-lastIndefOf.html ├── module-leftPad.html ├── module-leftTrim.html ├── module-prepend.html ├── module-prependArray.html ├── module-removeEmptyStrings.html ├── module-removeLeft.html ├── module-removeNonWords.html ├── module-removeSpaces.html ├── module-repeat.html ├── module-replace.html ├── module-reverse.html ├── module-rightPad.html ├── module-rightTrim.html ├── module-safeTruncate.html ├── module-shuffle.html ├── module-slugify.html ├── module-split.html ├── module-startsWith.html ├── module-substr.html ├── module-surround.html ├── module-toCamelCase.html ├── module-toDecamelize.html ├── module-toKebabCase.html ├── module-toLowerCase.html ├── module-toSnakeCase.html ├── module-toStudlyCaps.html ├── module-toUpperCase.html ├── module-transliterate.html ├── module-trim.html ├── module-truncate.html ├── module-urlDecode.html ├── module-urlEncode.html ├── prepend.js.html ├── prependarray.js.html ├── removeemptystrings.js.html ├── removeleft.js.html ├── removenonwords.js.html ├── removeright.js.html ├── removespaces.js.html ├── repeat.js.html ├── replace.js.html ├── reverse.js.html ├── rightpad.js.html ├── righttrim.js.html ├── safetruncate.js.html ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── Apache-License-2.0.txt │ │ ├── lang-css.js │ │ └── prettify.js ├── shuffle.js.html ├── slice.js.html ├── slugify.js.html ├── split.js.html ├── startswith.js.html ├── styles │ ├── jsdoc-default.css │ ├── prettify-jsdoc.css │ └── prettify-tomorrow.css ├── substr.js.html ├── surround.js.html ├── tocamelcase.js.html ├── todecamelize.js.html ├── tokebabcase.js.html ├── tolowercase.js.html ├── tosnakecase.js.html ├── tostudlycaps.js.html ├── touppercase.js.html ├── transliterate.js.html ├── trim.js.html ├── truncate.js.html ├── urlDecode.js.html └── urlencode.js.html ├── package.json ├── src ├── append.js ├── appendarray.js ├── at.js ├── base64decode.js ├── base64encode.js ├── between.js ├── bindecode.js ├── binencode.js ├── chars.js ├── collapsewhitespace.js ├── compare.js ├── contains.js ├── containsall.js ├── containsany.js ├── countsubstr.js ├── decdecode.js ├── decencode.js ├── endswith.js ├── ensureleft.js ├── ensureright.js ├── equal.js ├── first.js ├── format.js ├── hexdecode.js ├── hexencode.js ├── htmldecode.js ├── htmlencode.js ├── indexof.js ├── inequal.js ├── insert.js ├── islowercase.js ├── isstring.js ├── isuppercase.js ├── last.js ├── lastindexof.js ├── leftpad.js ├── lefttrim.js ├── lib │ ├── ascii.js │ ├── case.js │ ├── decode.js │ ├── encode.js │ ├── entitiesdecode.js │ ├── entitiesencode.js │ ├── numericalbase.js │ └── poparray.js ├── prepend.js ├── prependarray.js ├── removeemptystrings.js ├── removeleft.js ├── removenonwords.js ├── removeright.js ├── removespaces.js ├── repeat.js ├── replace.js ├── reverse.js ├── rightpad.js ├── righttrim.js ├── safetruncate.js ├── shuffle.js ├── slice.js ├── slugify.js ├── split.js ├── startswith.js ├── strman.js ├── substr.js ├── surround.js ├── tocamelcase.js ├── todecamelize.js ├── tokebabcase.js ├── tolowercase.js ├── tosnakecase.js ├── tostudlycaps.js ├── touppercase.js ├── transliterate.js ├── trim.js ├── truncate.js ├── urlDecode.js └── urlencode.js ├── strman.png ├── strman_new.png ├── test ├── append.strman.test.js ├── append.test.js ├── appendarray.strman.test.js ├── appendarray.test.js ├── at.strman.test.js ├── at.test.js ├── base64decode.strman.test.js ├── base64decode.test.js ├── base64encode.strman.test.js ├── base64encode.test.js ├── between.strman.test.js ├── between.test.js ├── bindecode.strman.test.js ├── bindecode.test.js ├── binencode.strman.test.js ├── binencode.test.js ├── chars.strman.test.js ├── chars.test.js ├── collapsewhitespace.strman.test.js ├── collapsewhitespace.test.js ├── compare.strman.test.js ├── compare.test.js ├── contains.strman.test.js ├── contains.test.js ├── containsall.strman.test.js ├── containsall.test.js ├── containsany.strman.test.js ├── containsany.test.js ├── countsubstr.strman.test.js ├── countsubstr.test.js ├── decdecode.strman.test.js ├── decdecode.test.js ├── decencode.strman.test.js ├── decencode.test.js ├── endswith.strman.test.js ├── endswith.test.js ├── ensureleft.strman.test.js ├── ensureleft.test.js ├── ensureright.strman.test.js ├── ensureright.test.js ├── equal.strman.test.js ├── equal.test.js ├── first.strman.test.js ├── first.test.js ├── format.strman.test.js ├── format.test.js ├── hexdecode.strman.test.js ├── hexdecode.test.js ├── hexencode.strman.test.js ├── hexencode.test.js ├── htmldecode.strman.test.js ├── htmldecode.test.js ├── htmlencode.strman.test.js ├── htmlencode.test.js ├── indexof.strman.test.js ├── indexof.test.js ├── inequal.strman.test.js ├── inequal.test.js ├── insert.strman.test.js ├── insert.test.js ├── islowercase.strman.test.js ├── islowercase.test.js ├── isstring.strman.test.js ├── isstring.test.js ├── isuppercase.strman.test.js ├── isuppercase.test.js ├── last.strman.test.js ├── last.test.js ├── lastindexof.strman.test.js ├── lastindexof.test.js ├── leftpad.strman.test.js ├── leftpad.test.js ├── lefttrim.strman.test.js ├── lefttrim.test.js ├── prepend.strman.test.js ├── prepend.test.js ├── prependarray.strman.test.js ├── prependarray.test.js ├── removeemptystrings.strman.test.js ├── removeemptystrings.test.js ├── removeleft.strman.test.js ├── removeleft.test.js ├── removenonwords.strman.test.js ├── removenonwords.test.js ├── removeright.strman.test.js ├── removeright.test.js ├── removespaces.strman.test.js ├── removespaces.test.js ├── repeat.strman.test.js ├── repeat.test.js ├── replace.strman.test.js ├── replace.test.js ├── reverse.strman.test.js ├── reverse.test.js ├── rightpad.strman.test.js ├── rightpad.test.js ├── righttrim.strman.test.js ├── righttrim.test.js ├── safetruncate.strman.test.js ├── safetruncate.test.js ├── shuffle.strman.test.js ├── shuffle.test.js ├── slice.strman.test.js ├── slice.test.js ├── slugify.strman.test.js ├── slugify.test.js ├── split.strman.test.js ├── split.test.js ├── startswith.strman.test.js ├── startswith.test.js ├── surround.strman.test.js ├── surround.test.js ├── tocamelcase.strman.test.js ├── tocamelcase.test.js ├── tokebabcase.strman.test.js ├── tokebabcase.test.js ├── tosnakecase.strman.test.js ├── tosnakecase.test.js ├── tostudlycaps.strman.test.js ├── tostudlycaps.test.js ├── transliterate.strman.test.js ├── transliterate.test.js ├── trim.strman.test.js ├── trim.test.js ├── truncate.strman.test.js ├── truncate.test.js ├── urldecode.strman.test.js ├── urldecode.test.js ├── urlencode.strman.test.js └── urlencode.test.js ├── yarn-error.log └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | defaults: &defaults 4 | working_directory: ~/repo 5 | docker: 6 | - image: circleci/node:9.11 7 | 8 | jobs: 9 | test: 10 | <<: *defaults 11 | steps: 12 | - checkout 13 | - restore_cache: 14 | keys: 15 | - v1-dependencies- 16 | # fallback to using the latest cache if no exact match is found 17 | - v1-dependencies- 18 | 19 | - run: npm install 20 | - run: 21 | name: Run tests 22 | command: | 23 | npm run lint 24 | npm test 25 | - save_cache: 26 | paths: 27 | - node_modules 28 | key: v1-dependencies- 29 | 30 | - persist_to_workspace: 31 | root: ~/repo 32 | paths: . 33 | 34 | deploy: 35 | <<: *defaults 36 | steps: 37 | - attach_workspace: 38 | at: ~/repo 39 | - run: 40 | name: Authenticate with registry 41 | command: | 42 | echo "//registry.npmjs.org/:_authToken=${TOKEN_NPM}" > ~/.npmrc 43 | echo "//registry.npmjs.org/:_password=${PASSWORD_NPM}" >> ~/.npmrc 44 | echo "//registry.npmjs.org/:username=dleitee" >> ~/.npmrc 45 | echo "//registry.npmjs.org/:email=dleitee@gmail.com" >> ~/.npmrc 46 | - run: 47 | name: Publish package 48 | command: | 49 | npm publish 50 | npm run build:packages 51 | npm run coveralls 52 | 53 | workflows: 54 | version: 2 55 | test-deploy: 56 | jobs: 57 | - test: 58 | filters: 59 | tags: 60 | only: /^v.*/ 61 | - deploy: 62 | requires: 63 | - test 64 | filters: 65 | tags: 66 | only: /^v.*/ 67 | branches: 68 | ignore: /.*/ 69 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | engines: 2 | eslint: 3 | enabled: true 4 | channel: "eslint-2" 5 | duplication: 6 | enabled: true 7 | config: 8 | languages: 9 | - javascript 10 | ratings: 11 | paths: 12 | - src/** 13 | exclude_paths: 14 | - test/**/* 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | 8 | [*.{js}] 9 | charset = utf-8 10 | indent_size = 4 11 | indent_style = space 12 | 13 | [{package.json,bower.json,.travis.yml}] 14 | indent_size = 2 15 | indent_style = space 16 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | 7 | [lints] 8 | 9 | [options] 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | _site 3 | coverage 4 | docs.json 5 | lib 6 | -------------------------------------------------------------------------------- /.jsdocrc: -------------------------------------------------------------------------------- 1 | { 2 | "tags": { 3 | "allowUnknownTags": true, 4 | "dictionaries": ["jsdoc"] 5 | }, 6 | "source": { 7 | "include": ["src", "package.json", "README.md"], 8 | "includePattern": ".js$", 9 | "excludePattern": "(node_modules/|docs)" 10 | }, 11 | "plugins": [ 12 | "node_modules/jsdoc-babel", 13 | "plugins/markdown" 14 | ], 15 | "templates": { 16 | "cleverLinks": false, 17 | "monospaceLinks": true, 18 | "useLongnameInNav": false 19 | }, 20 | "opts": { 21 | "destination": "./docs/", 22 | "encoding": "utf8", 23 | "private": true, 24 | "recurse": true, 25 | "template": "./node_modules/minami" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | build 3 | src 4 | .codeclimate.yml 5 | .editorconfig 6 | .travis.yml 7 | -------------------------------------------------------------------------------- /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 contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at dleitee@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | 1. Fork it! 4 | 2. Create your feature branch: `git checkout -b my-new-feature` 5 | 3. Commit your changes: `git commit -m 'Add some feature'` 6 | 4. Push to the branch: `git push origin my-new-feature` 7 | 5. Submit a pull request :) 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Daniel Leite de Oliveira 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | [![CircleCI](https://circleci.com/gh/dleitee/strman.svg?style=svg)](https://circleci.com/gh/dleitee/strman) 6 | [![Coverage Status](https://coveralls.io/repos/github/dleitee/strman/badge.svg?branch=master)](https://coveralls.io/github/dleitee/strman?branch=master) 7 | [![Code Climate](https://codeclimate.com/github/dleitee/strman/badges/gpa.svg)](https://codeclimate.com/github/dleitee/strman) [![Greenkeeper badge](https://badges.greenkeeper.io/dleitee/strman.svg)](https://greenkeeper.io/) 8 | 9 | A Javascript string manipulation library. 10 | 11 | ## Install 12 | 13 | strman v2.0.0 is available on npm/yarn: 14 | ``` 15 | npm install strman --save 16 | yarn add strman 17 | ``` 18 | 19 | ## Documentation 20 | 21 | [https://dleitee.github.io/strman/](https://dleitee.github.io/strman/) 22 | 23 | ## Usage 24 | 25 | ### With ES6/import 26 | 27 | ```javascript 28 | import { slugify } from 'strman' 29 | 30 | const title = "A Javascript string manipulation library."; 31 | slugify(title); 32 | // => "a-javascript-string-manipulation-library" 33 | ``` 34 | 35 | ### With require 36 | 37 | ```javascript 38 | const slugify = require('strman').slugify; 39 | 40 | const title = 'A Javascript string manipulation library.' 41 | slugify(title) 42 | // => "a-javascript-string-manipulation-library" 43 | ``` 44 | 45 | ## Credits 46 | 47 | - [Stringy](https://github.com/danielstjules/Stringy) 48 | 49 | 50 | # Contributing 51 | 52 | Want to contribute? [Follow these recommendations.](https://github.com/dleitee/strman/blob/master/CONTRIBUTING.md) 53 | 54 | # LICENSE 55 | 56 | The MIT License (MIT) 57 | 58 | Copyright (c) 2015 Daniel Leite de Oliveira 59 | 60 | Permission is hereby granted, free of charge, to any person obtaining a copy 61 | of this software and associated documentation files (the "Software"), to deal 62 | in the Software without restriction, including without limitation the rights 63 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 64 | copies of the Software, and to permit persons to whom the Software is 65 | furnished to do so, subject to the following conditions: 66 | 67 | The above copyright notice and this permission notice shall be included in 68 | all copies or substantial portions of the Software. 69 | 70 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 71 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 72 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 73 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 74 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 75 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 76 | THE SOFTWARE. 77 | 78 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | 3 | import generate from './generate' 4 | 5 | const filesIgnore = ['lib', 'strman.js'] 6 | 7 | const files = fs.readdirSync('./src/').filter(file => filesIgnore.indexOf(file) === -1) 8 | const libFiles = fs.readdirSync('./src/lib/') 9 | 10 | files.forEach((value) => { 11 | generate(`src/${value}`) 12 | }) 13 | 14 | libFiles.forEach((value) => { 15 | generate(`src/lib/${value}`) 16 | }) 17 | -------------------------------------------------------------------------------- /build/code.js: -------------------------------------------------------------------------------- 1 | import { getRequires } from './dependecies' 2 | 3 | export default (code, dependencies) => `${getRequires(dependencies)}${code}` 4 | -------------------------------------------------------------------------------- /build/dependecies.js: -------------------------------------------------------------------------------- 1 | import prefix from './prefix' 2 | 3 | export const getFileName = dependency => prefix(dependency.file.replace(/.+\/(lib\/)*/, '')) 4 | 5 | export const getRequires = dependencies => dependencies.reduce((requires, file) => { 6 | const newRequires = file.specifiers.map((dependency) => { 7 | if (dependency.type === 'ImportSpecifier') { 8 | return `var ${dependency.name} = require('${getFileName(file)}').${dependency.name}` 9 | } 10 | return `var ${dependency.name} = require('${getFileName(file)}')` 11 | }).join('\n') 12 | return `${requires}${newRequires}\n` 13 | }, '') 14 | -------------------------------------------------------------------------------- /build/generate.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import { exec } from 'child_process' 3 | 4 | import { transformFileSync } from 'babel-core' 5 | import showdeps from 'showdeps' 6 | 7 | import packageJson from '../package.json' 8 | 9 | import makePackage from './package' 10 | import makeCode from './code' 11 | import makeReadme from './readme' 12 | import { getFileName } from './dependecies' 13 | 14 | export default async (filename) => { 15 | console.info(`Executing: ${filename}\n`) 16 | const tmpDir = '/tmp/' 17 | const workdir = fs.mkdtempSync(tmpDir) 18 | const libname = filename.match(/[\w]+.js$/g)[0].replace('.js', '').toLowerCase() 19 | const file = fs.readFileSync(filename, { encoding: 'UTF-8' }) 20 | 21 | const deps = showdeps(file) 22 | const dependencies = deps.map(getFileName) 23 | 24 | const code = transformFileSync(filename, { 25 | plugins: ['transform-remove-import', 'add-module-exports', 'transform-remove-strict-mode'], 26 | }).code 27 | 28 | const library = {} 29 | library.code = makeCode(code, deps) 30 | library.package = makePackage(libname, packageJson.version, dependencies) 31 | library.readme = makeReadme(libname, packageJson.version) 32 | 33 | const options = { encoding: 'utf-8' } 34 | 35 | fs.writeFileSync(`${workdir}/index.js`, library.code, options) 36 | fs.writeFileSync(`${workdir}/package.json`, library.package, options) 37 | fs.writeFileSync(`${workdir}/readme.md`, library.readme, options) 38 | 39 | await exec(`cd ${workdir} && npm publish`, (error, stdout, stderr) => { 40 | console.info(filename) 41 | if (error) { 42 | console.error(`exec error: ${error}`) 43 | return 44 | } 45 | console.info(`stdout: ${stdout}`) 46 | console.info(`stderr: ${stderr}`) 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /build/package.js: -------------------------------------------------------------------------------- 1 | import prefix from './prefix' 2 | 3 | const mapDependencies = (dependencies, version) => 4 | dependencies.map(dependency => `"${dependency}":"${version}"`) 5 | 6 | const getDependencies = (dependencies, version) => { 7 | if (dependencies.length) { 8 | return `"dependencies": { 9 | \t${mapDependencies(dependencies, version).join(',\n\t')} 10 | },` 11 | } 12 | 13 | return '' 14 | } 15 | 16 | export default (name, version, dependencies = []) => ` 17 | { 18 | "name": "${prefix(name)}", 19 | "version": "${version}", 20 | "description": "The [strman](https://github.com/dleitee/strman) method \`${name}\` exported as a [Node.js](https://nodejs.org/) module.", 21 | "main": "index.js", 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/dleitee/strman.git" 25 | }, 26 | "keywords": [ 27 | "string", 28 | "manipulate", 29 | "str", 30 | "manipulation", 31 | "strman", 32 | "${name}" 33 | ], 34 | ${getDependencies(dependencies, version)} 35 | "author": "Daniel Leite de Oliveira ", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/dleitee/strman/issues" 39 | }, 40 | "homepage": "https://github.com/dleitee/strman#readme" 41 | } 42 | 43 | ` 44 | -------------------------------------------------------------------------------- /build/prefix.js: -------------------------------------------------------------------------------- 1 | export default name => `strman.${name}` 2 | -------------------------------------------------------------------------------- /build/readme.js: -------------------------------------------------------------------------------- 1 | import prefix from './prefix' 2 | 3 | export default (libname, version) => ` 4 | # ${prefix(libname)} v${version} 5 | 6 | The [strman](https://github.com/dleitee/strman) method \`${libname}\` exported as a [Node.js](https://nodejs.org/) module. 7 | 8 | ## Installation 9 | 10 | Using npm: 11 | \`\`\`bash 12 | $ {sudo -H} npm i -g npm 13 | $ npm i --save ${prefix(libname)} 14 | \`\`\` 15 | 16 | In Node.js: 17 | \`\`\`js 18 | var ${libname} = require('${prefix(libname)}'); 19 | \`\`\` 20 | 21 | # Contributing 22 | 23 | Want to contribute? [Follow these recommendations.](https://github.com/dleitee/strman/blob/master/CONTRIBUTING.md) 24 | 25 | # LICENSE 26 | 27 | The MIT License (MIT) 28 | 29 | Copyright (c) 2015 Daniel Leite de Oliveira 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining a copy 32 | of this software and associated documentation files (the "Software"), to deal 33 | in the Software without restriction, including without limitation the rights 34 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | copies of the Software, and to permit persons to whom the Software is 36 | furnished to do so, subject to the following conditions: 37 | 38 | The above copyright notice and this permission notice shall be included in 39 | all copies or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 47 | THE SOFTWARE. 48 | ` 49 | -------------------------------------------------------------------------------- /docs/chars.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | chars.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

chars.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
/**
42 |  * @module chars
43 |  * @description
44 |  * Returns an array consisting of the characters in the string.
45 |  * ## Install
46 |  * Install all functions of strman
47 |  * ```sh
48 |  * yarn add strman
49 |  * ```
50 |  * or just the chars function
51 |  * ```sh
52 |  * yarn add strman.chars
53 |  * ```
54 |  * ## Usage
55 |  * ```javascript
56 |  * import { chars } from 'strman'
57 |  * // OR
58 |  * import chars from 'strman.chars'
59 |  * ```
60 |  * @param {String} value The input string
61 |  * @example
62 |  * chars('abc')
63 |  * // => ['a', 'b', 'c']
64 |  * @returns {String[]} The array with the single characters of `value`
65 |  */
66 | export default value => value.split('')
67 | 
68 |
69 |
70 | 71 | 72 | 73 | 74 |
75 | 76 |
77 | 78 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /docs/equal.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | equal.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

equal.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
/**
42 |  * @module equal
43 |  * @description
44 |  * Tests if two strings are equal.
45 |  * ## Install
46 |  * Install all functions of strman
47 |  * ```sh
48 |  * yarn add strman
49 |  * ```
50 |  * or just the equal function
51 |  * ```sh
52 |  * yarn add strman.equal
53 |  * ```
54 |  * ## Usage
55 |  * ```javascript
56 |  * import { equal } from 'strman'
57 |  * // OR
58 |  * import equal from 'strman.equal'
59 |  * ```
60 |  * @param {String} stringA - String for the comparative
61 |  * @param {String} stringB - String to be compared
62 |  * @example
63 |  * equal('foo', 'foo')
64 |  * // => true
65 |  * @returns {Boolean}  `stringA`is equal `stringB`
66 |  */
67 | export default (stringA, stringB) => stringA === stringB
68 | 
69 |
70 |
71 | 72 | 73 | 74 | 75 |
76 | 77 |
78 | 79 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Semibold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Semibold-webfont.ttf -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-Semibold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-SemiboldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/docs/fonts/OpenSans-SemiboldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /docs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: hsl(104, 100%, 24%); 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: hsl(104, 100%, 24%); } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: hsl(240, 100%, 50%); } 17 | 18 | /* a comment */ 19 | .com { 20 | color: hsl(0, 0%, 60%); } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: hsl(240, 100%, 32%); } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: hsl(240, 100%, 40%); } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #000000; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #000000; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #000000; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "strman", 3 | "version": "2.0.0", 4 | "description": 5 | "A Javascript string manipulation library without npm dependences.", 6 | "main": "lib/strman.js", 7 | "directories": { 8 | "test": "test" 9 | }, 10 | "scripts": { 11 | "build:packages": "babel-node build/build.js", 12 | "build:strman": "babel src --out-dir lib", 13 | "prepublish": "npm run build:strman", 14 | "postpublish": "rm -rf ./lib", 15 | "test": "jest --coverage --expand -i", 16 | "test-watch": "jest --watch", 17 | "lint": "eslint src test", 18 | "coveralls": 19 | "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", 20 | "docs": "jsdoc --configure .jsdocrc --verbose -r" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/dleitee/strman.git" 25 | }, 26 | "keywords": ["string", "manipulate", "str", "manipulation", "strman"], 27 | "babel": { 28 | "presets": ["es2015", "stage-0", "flow"] 29 | }, 30 | "eslintConfig": { 31 | "parser": "babel-eslint", 32 | "extends": "airbnb/base", 33 | "env": { 34 | "browser": true, 35 | "node": true, 36 | "jest": true 37 | }, 38 | "rules": { 39 | "semi": [2, "never"], 40 | "no-console": [ 41 | 2, 42 | { 43 | "allow": ["warn", "info", "error"] 44 | } 45 | ], 46 | "import/named": 2, 47 | "no-multiple-empty-lines": [ 48 | "error", 49 | { 50 | "max": 1, 51 | "maxEOF": 1, 52 | "maxBOF": 0 53 | } 54 | ], 55 | "import/order": [ 56 | "error", 57 | { 58 | "groups": ["builtin", "external", "parent", "sibling", "index"], 59 | "newlines-between": "always" 60 | } 61 | ], 62 | "no-lenght/no-lenght": "error" 63 | }, 64 | "plugins": ["no-lenght"] 65 | }, 66 | "author": "Daniel Leite de Oliveira ", 67 | "license": "MIT", 68 | "bugs": { 69 | "url": "https://github.com/dleitee/strman/issues" 70 | }, 71 | "homepage": "https://github.com/dleitee/strman#readme", 72 | "devDependencies": { 73 | "babel-cli": "^6.26.0", 74 | "babel-core": "^6.7.6", 75 | "babel-eslint": "^9.0.0", 76 | "babel-istanbul": "^0.12.2", 77 | "babel-jest": "^23.0.1", 78 | "babel-plugin-add-module-exports": "^1.0.0", 79 | "babel-plugin-transform-remove-import": "^1.0.0", 80 | "babel-plugin-transform-remove-strict-mode": "^0.0.2", 81 | "babel-preset-es2015": "^6.6.0", 82 | "babel-preset-flow": "^6.23.0", 83 | "babel-preset-stage-0": "^6.22.0", 84 | "babel-register": "^6.7.2", 85 | "coveralls": "^3.0.1", 86 | "dox": "^0.9.0", 87 | "eslint": "^6.0.0", 88 | "eslint-config-airbnb": "^16.1.0", 89 | "eslint-plugin-import": "^2.2.0", 90 | "eslint-plugin-no-lenght": "^1.0.2-0", 91 | "flow-bin": "^0.78.0", 92 | "jest": "^23.1.0", 93 | "jsdoc": "^3.4.3", 94 | "jsdoc-babel": "^0.5.0", 95 | "minami": "^1.1.1", 96 | "showdeps": "^1.0.0", 97 | "yarn": "^1.7.0" 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/append.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import appendArray from './appendarray' 3 | 4 | /** 5 | * @module append 6 | * @description 7 | * Append Strings on Value with spreaded arguments 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the append function 14 | * ```sh 15 | * yarn add strman.append 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { append } from 'strman' 20 | * // OR 21 | * import append from 'strman.append' 22 | * ``` 23 | * @param {String} value Initial value 24 | * @param {String} appends Spreaded array with strings to append 25 | * @example 26 | * append('s', 'tr', 'm', 'an') 27 | * // => 'strman' 28 | * @returns {String} The concatenated string 29 | */ 30 | export default (value: string, ...appends: Array): string => appendArray(value, appends) 31 | -------------------------------------------------------------------------------- /src/appendarray.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module appendArray 4 | * @description 5 | * Append Array of Strings on Value 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the appendArray function 12 | * ```sh 13 | * yarn add strman.appendarray 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { appendArray } from 'strman' 18 | * // OR 19 | * import appendArray from 'strman.appendarray' 20 | * ``` 21 | * @param {String} value String initial 22 | * @param {String[]} append Array with strings to append 23 | * @example 24 | * appendArray('s', ['tr', 'm', 'an']) 25 | * // => 'strman' 26 | * @returns {String} The concatenated string 27 | */ 28 | export default (value: string, appends: Array = []): string => { 29 | if (appends.length === 0) { 30 | return value 31 | } 32 | return value + appends.join('') 33 | } 34 | -------------------------------------------------------------------------------- /src/at.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import substr from './substr' 3 | 4 | /** 5 | * @module at 6 | * @description 7 | * Get the character at index 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the at function 14 | * ```sh 15 | * yarn add strman.at 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { at } from 'strman' 20 | * // OR 21 | * import at from 'strman.at' 22 | * ``` 23 | * @param {String} value The input string 24 | * @param {Number} index The index for which to extract the character 25 | * @example 26 | * at('abc', 1) 27 | * // => 'b' 28 | * @returns {String} The character at position index 29 | */ 30 | export default (value: string, index: number): string => substr(value, index, 1) 31 | -------------------------------------------------------------------------------- /src/base64decode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module base64decode 4 | * @description 5 | * Decodes data encoded with MIME base64 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the base64decode function 12 | * ```sh 13 | * yarn add strman.base64decode 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { base64decode } from 'strman' 18 | * // OR 19 | * import base64decode from 'strman.base64decode' 20 | * ``` 21 | * @param {String} value - The data to decode. 22 | * @example 23 | * base64Decode('c3RybWFu') 24 | * // => 'strman' 25 | * @returns {String} The base64 decoded data. 26 | */ 27 | export default (value: string): string => 28 | Buffer.from(value, 'base64').toString() 29 | -------------------------------------------------------------------------------- /src/base64encode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module base64encode 4 | * @description 5 | * Encodes data with MIME base64. 6 | * 7 | * Base64-encoded data takes about 33% more space than the original data. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the base64encode function 14 | * ```sh 15 | * yarn add strman.base64encode 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { base64encode } from 'strman' 20 | * // OR 21 | * import base64encode from 'strman.base64encode' 22 | * ``` 23 | * @param {String} value - The data to encode. 24 | * @example 25 | * base64Encode('strman') 26 | * // => 'c3RybWFu' 27 | * @returns {String} The base64 encoded data. 28 | */ 29 | export default (value: string): string => Buffer.from(value).toString('base64') 30 | -------------------------------------------------------------------------------- /src/between.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import pop from './lib/poparray' 3 | import substr from './substr' 4 | import split from './split' 5 | import indexOf from './indexof' 6 | 7 | /** 8 | * @module between 9 | * @description 10 | * Returns array with strings between `start` and `end` 11 | * ## Install 12 | * Install all functions of strman 13 | * ```sh 14 | * yarn add strman 15 | * ``` 16 | * or just the between function 17 | * ```sh 18 | * yarn add strman.between 19 | * ``` 20 | * ## Usage 21 | * ```javascript 22 | * import { between } from 'strman' 23 | * // OR 24 | * import between from 'strman.between' 25 | * ``` 26 | * @param {String} value Input string 27 | * @param {String} start The start string to look for 28 | * @param {String} end The end string to look for 29 | * @example 30 | * strman.between('[abc][def]', '[', ']') 31 | * // => ['abc', 'def'] 32 | * @returns {String[]} An array with all the matches between a pair of `start` and `end` 33 | */ 34 | export default (value: string, start: string, end: string): Array => 35 | pop(split(value, end).map(text => substr(text, indexOf(text, start) + start.length))) 36 | -------------------------------------------------------------------------------- /src/bindecode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { LENGTH_BINARY, BASE_BINARY } from './lib/numericalbase' 3 | import decode from './lib/decode' 4 | 5 | /** 6 | * @module binDecode 7 | * @description 8 | * Convert binary unicode (16 digits) string to string chars 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the binDecode function 15 | * ```sh 16 | * yarn add strman.bindecode 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { binDecode } from 'strman' 21 | * // OR 22 | * import binDecode from 'strman.bindecode' 23 | * ``` 24 | * @param {String} value Value to decode 25 | * @example 26 | * const binary = '00000000011100110000000001110100000000000111001000000000011011010000000001100001' 27 | * binDecode(binary) 28 | * // => 'strman' 29 | * @returns {String} String decoded. 30 | */ 31 | export default (value: string): string => decode(value, LENGTH_BINARY, BASE_BINARY) 32 | -------------------------------------------------------------------------------- /src/binencode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { LENGTH_BINARY, BASE_BINARY } from './lib/numericalbase' 3 | import encode from './lib/encode' 4 | 5 | /** 6 | * @module binEncode 7 | * @description 8 | * Convert string chars to binary unicode (16 digits) 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the binEncode function 15 | * ```sh 16 | * yarn add strman.binencode 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { binEncode } from 'strman' 21 | * // OR 22 | * import binEncode from 'strman.binencode' 23 | * ``` 24 | * @param {String} value - Value to encode 25 | * @example 26 | * binEncode('strman') 27 | * // => '00000000011100110000000001110100000000000111001000000000011011010000000001100001' 28 | * @returns {String} String in binary format. 29 | */ 30 | export default (value: string): string => encode(value, LENGTH_BINARY, BASE_BINARY) 31 | -------------------------------------------------------------------------------- /src/chars.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module chars 4 | * @description 5 | * Returns an array consisting of the characters in the string. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the chars function 12 | * ```sh 13 | * yarn add strman.chars 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { chars } from 'strman' 18 | * // OR 19 | * import chars from 'strman.chars' 20 | * ``` 21 | * @param {String} value The input string 22 | * @example 23 | * chars('abc') 24 | * // => ['a', 'b', 'c'] 25 | * @returns {String[]} The array with the single characters of `value` 26 | */ 27 | export default (value: string): Array => value.split('') 28 | -------------------------------------------------------------------------------- /src/collapsewhitespace.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import trim from './trim' 3 | import replace from './replace' 4 | /** 5 | * @module collapseWhitespace 6 | * @description 7 | * Replaces consecutive whitespace characters with a single space. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the collapseWhitespace function 14 | * ```sh 15 | * yarn add strman.collapsewhitespace 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { collapseWhitespace } from 'strman' 20 | * // OR 21 | * import collapseWhitespace from 'strman.collapsewhitespace' 22 | * ``` 23 | * @param {String} value The input string 24 | * @example 25 | * collapseWhitespace(' a b c ') 26 | * // => 'a b c' 27 | * @returns {String} The whitespace collapsed string 28 | */ 29 | export default (value: string): string => trim(replace(value, '\\s\\s+', ' ')) 30 | -------------------------------------------------------------------------------- /src/compare.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import equal from './equal' 3 | 4 | /** 5 | * @module compare 6 | * @description 7 | * Compares two strings to each other. If they are equivalent, a zero is returned. Otherwise, 8 | * most of these routines will return a positive or negative result corresponding to whether stringA 9 | * is lexicographically greater than, or less than, respectively, than stringB. 10 | * 11 | * if `stringA` > `stringB` return 1 12 | * 13 | * if `stringA` < `stringB` return -1 14 | * 15 | * if `stringA` = `stringB` return 0 16 | * ## Install 17 | * Install all functions of strman 18 | * ```sh 19 | * yarn add strman 20 | * ``` 21 | * or just the compare function 22 | * ```sh 23 | * yarn add strman.compare 24 | * ``` 25 | * ## Usage 26 | * ```javascript 27 | * import { compare } from 'strman' 28 | * // OR 29 | * import compare from 'strman.compare' 30 | * ``` 31 | * @param {String} stringA - String for the comparative 32 | * @param {String} stringB - String to be compared 33 | * @example 34 | * compare('foo', 'bar') 35 | * // => 1 36 | * @returns {Number} 37 | */ 38 | export default (stringA: string, stringB: string): number => { 39 | if (equal(stringA, stringB)) { 40 | return 0 41 | } 42 | return stringA > stringB ? 1 : -1 43 | } 44 | -------------------------------------------------------------------------------- /src/contains.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import indexOf from './indexof' 3 | /** 4 | * @module contains 5 | * @description 6 | * Verifies that the needle is contained in value 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the contains function 13 | * ```sh 14 | * yarn add strman.contains 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { contains } from 'strman' 19 | * // OR 20 | * import contains from 'strman.contains' 21 | * ``` 22 | * @param {String} value The input string 23 | * @param {String} needle The string which is checked to be contained within `value` 24 | * @param {Boolean} [caseSensitive=true] Use case (in-)sensitive matching 25 | * @example 26 | * const title = 'Daniel Leite' 27 | * const needle = 'leite' 28 | * contains(title, needle, false) 29 | * // => true 30 | * @returns {Boolean} True if `needle` is contained 31 | */ 32 | export default (value: string, needle: string, caseSensitive: boolean = true): boolean => 33 | indexOf(value, needle, 0, caseSensitive) > -1 34 | -------------------------------------------------------------------------------- /src/containsall.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import contains from './contains' 3 | 4 | const containsAll = ( 5 | value: string, 6 | caseSensitive: boolean, 7 | previous: boolean, 8 | current: string, 9 | ): boolean => { 10 | if (!contains(value, current, caseSensitive)) { 11 | return false 12 | } 13 | return previous && true 14 | } 15 | 16 | /** 17 | * @module containsAll 18 | * @description 19 | * Verifies that all needles are contained in value 20 | * ## Install 21 | * Install all functions of strman 22 | * ```sh 23 | * yarn add strman 24 | * ``` 25 | * or just the containsAll function 26 | * ```sh 27 | * yarn add strman.containsall 28 | * ``` 29 | * ## Usage 30 | * ```javascript 31 | * import { containsAll } from 'strman' 32 | * // OR 33 | * import containsAll from 'strman.containsall' 34 | * ``` 35 | * @param {String} value The input string 36 | * @param {String[]} needles An array of strings which are checked to be contained within `value` 37 | * @param {Boolean} [caseSensitive=true] Use case (in-)sensitive matching 38 | * @example 39 | * const title = 'Daniel Leite' 40 | * const needles = ['Leite', 'Daniel'] 41 | * containsAll(title, needles) 42 | * // => true 43 | * @returns {Boolean} True if all `needles` are contained 44 | */ 45 | export default (value: string, needles: Array, caseSensitive: boolean = true): boolean => { 46 | if (needles.length > 0) { 47 | return needles.reduce(containsAll.bind(this, value, caseSensitive), true) 48 | } 49 | 50 | return false 51 | } 52 | -------------------------------------------------------------------------------- /src/containsany.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import contains from './contains' 3 | 4 | const containsAny = ( 5 | value: string, 6 | caseSensitive: boolean, 7 | previous: boolean, 8 | current: string, 9 | ): boolean => { 10 | if (contains(value, current, caseSensitive)) { 11 | return true 12 | } 13 | return previous 14 | } 15 | 16 | /** 17 | * @module containsAny 18 | * @description 19 | * Verifies that one or more of needles are contained in value 20 | * ## Install 21 | * Install all functions of strman 22 | * ```sh 23 | * yarn add strman 24 | * ``` 25 | * or just the containsAny function 26 | * ```sh 27 | * yarn add strman.containsany 28 | * ``` 29 | * ## Usage 30 | * ```javascript 31 | * import { containsAny } from 'strman' 32 | * // OR 33 | * import containsAny from 'strman.containsany' 34 | * ``` 35 | * @param {String} value The input string 36 | * @param {String[]} needles An array of string which are checked to be contained within `value` 37 | * @param {Boolean} [caseSensitive=true] Use case (in-)sensitive matching 38 | * @example 39 | * const title = 'Daniel Leite' 40 | * const needles = ['Leite', 'Oliveira'] 41 | * containsAny(title, needles) 42 | * // => true 43 | * @returns {Boolean} True if at least one of `needles` is contained 44 | */ 45 | export default (value: string, needles: Array, caseSensitive: boolean = true): boolean => 46 | needles.reduce(containsAny.bind(this, value, caseSensitive), false) 47 | -------------------------------------------------------------------------------- /src/countsubstr.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import indexOf from './indexof' 3 | import getCase from './lib/case' 4 | 5 | const countSubstr = ( 6 | value: string, 7 | substr: string, 8 | allowOverlapping: boolean = false, 9 | position: number = 0, 10 | count: number = 0, 11 | ): number => { 12 | let currentPosition = indexOf(value, substr, position) 13 | if (currentPosition === -1) { 14 | return count 15 | } 16 | if (!allowOverlapping) { 17 | currentPosition += substr.length - 1 18 | } 19 | return countSubstr(value, substr, allowOverlapping, currentPosition + 1, count + 1) 20 | } 21 | 22 | /** 23 | * @module countSubstr 24 | * @description 25 | * Count the number of times substr appears in value 26 | * ## Install 27 | * Install all functions of strman 28 | * ```sh 29 | * yarn add strman 30 | * ``` 31 | * or just the countSubstr function 32 | * ```sh 33 | * yarn add strman.countsubstr 34 | * ``` 35 | * ## Usage 36 | * ```javascript 37 | * import { countSubstr } from 'strman' 38 | * // OR 39 | * import countSubstr from 'strman.countsubstr' 40 | * ``` 41 | * @param {String} value The input string 42 | * @param {String} substr The substring to look for 43 | * @param {Boolean} [caseSensitive=true] Use case (in-)sensitive matching 44 | * @param {Boolean} [allowOverlapping=false] Allow overlapping substrings to be counted 45 | * @example 46 | * const title = 'Daniel Leite' 47 | * const substr = 'Leite' 48 | * countSubstr(title, substr) 49 | * // => 1 50 | * @returns {Number} The number of matches 51 | */ 52 | export default ( 53 | value: string, 54 | substr: string, 55 | caseSensitive: boolean = true, 56 | allowOverlapping: boolean = false, 57 | ): number => 58 | countSubstr(getCase(value, caseSensitive), getCase(substr, caseSensitive), allowOverlapping) 59 | -------------------------------------------------------------------------------- /src/decdecode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { LENGTH_DECIMAL, BASE_DECIMAL } from './lib/numericalbase' 3 | import decode from './lib/decode' 4 | 5 | /** 6 | * @module decDecode 7 | * @description 8 | * Convert binary unicode (16 digits) string to string chars 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the decDecode function 15 | * ```sh 16 | * yarn add strman.decdecode 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { decDecode } from 'strman' 21 | * // OR 22 | * import decDecode from 'strman.decdecode' 23 | * ``` 24 | * @param {String} value - Value to decode 25 | * @example 26 | * decDecode('001150011600114001090009700110') 27 | * // => 'strman' 28 | * @returns {String} String decoded. 29 | */ 30 | export default (value: string): string => decode(value, LENGTH_DECIMAL, BASE_DECIMAL) 31 | -------------------------------------------------------------------------------- /src/decencode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { LENGTH_DECIMAL, BASE_DECIMAL } from './lib/numericalbase' 3 | import encode from './lib/encode' 4 | /** 5 | * @module decEncode 6 | * @description 7 | * Convert string chars to decimal unicode (5 digits) 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the decEncode function 14 | * ```sh 15 | * yarn add strman.decencode 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { decEncode } from 'strman' 20 | * // OR 21 | * import decEncode from 'strman.decencode' 22 | * ``` 23 | * @param {String} value - Value to encode 24 | * @example 25 | * decEncode('strman') 26 | * // => '001150011600114001090009700110' 27 | * @returns {String} String in decimal format. 28 | */ 29 | export default (value: string): string => encode(value, LENGTH_DECIMAL, BASE_DECIMAL) 30 | -------------------------------------------------------------------------------- /src/endswith.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import indexOf from './indexof' 3 | 4 | const isInteger = (value: number): boolean => 5 | // eslint-disable-next-line no-restricted-globals 6 | typeof value === 'number' && isFinite(value) && Math.floor(value) === value 7 | 8 | const getPosition = ( 9 | value: string, 10 | search: string, 11 | position: number, 12 | ): number => { 13 | if ( 14 | !isInteger(position) || 15 | position > value.length || 16 | position < search.length 17 | ) { 18 | return value.length - search.length 19 | } 20 | return position - search.length 21 | } 22 | 23 | /** 24 | * @module endsWith 25 | * @description 26 | * Test if `value` ends with `search` 27 | * ## Install 28 | * Install all functions of strman 29 | * ```sh 30 | * yarn add strman 31 | * ``` 32 | * or just the endsWith function 33 | * ```sh 34 | * yarn add strman.endswith 35 | * ``` 36 | * ## Usage 37 | * ```javascript 38 | * import { endsWith } from 'strman' 39 | * // OR 40 | * import endsWith from 'strman.endswith' 41 | * ``` 42 | * @param {String} value The input string 43 | * @param {String} search The string to search for 44 | * @param {Number} [position] The start position/index within `value` to start searching 45 | * @param {Boolean} [caseSensitive=true] Use case (in-)sensitive matching 46 | * @example 47 | * const value = 'Daniel Leite' 48 | * const search = 'Leite' 49 | * endsWith(value, search) 50 | * // => true 51 | * @returns {Boolean} True if `value` ends with `search` 52 | */ 53 | export default ( 54 | value: string, 55 | search: string, 56 | position: number = 0, 57 | caseSensitive: boolean = true, 58 | ): boolean => { 59 | const newPosition = getPosition(value, search, position) 60 | const lastIndex = indexOf(value, search, newPosition, caseSensitive) 61 | return lastIndex !== -1 && lastIndex === newPosition 62 | } 63 | -------------------------------------------------------------------------------- /src/ensureleft.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import startsWith from './startswith' 3 | import append from './append' 4 | /** 5 | * @module ensureLeft 6 | * @description 7 | * Ensures that the `value` begins with `substr`. If it doesn't, it's prepended. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the ensureLeft function 14 | * ```sh 15 | * yarn add strman.ensureleft 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { ensureLeft } from 'strman' 20 | * // OR 21 | * import ensureLeft from 'strman.ensureleft' 22 | * ``` 23 | * @param {String} value The input string 24 | * @param {String} substr The substr to be ensured to be left 25 | * @param {Boolean} [caseSensitive=true] 26 | * Use case (in-)sensitive matching for determining if `value` already starts with `substr` 27 | * @example 28 | * const value = 'Leite' 29 | * const substr = 'Daniel ' 30 | * ensureLeft(value, substr) 31 | * // => 'Daniel Leite' 32 | * @returns {String} The string which is guarenteed to start with `substr` 33 | */ 34 | export default (value: string, substr: string, caseSensitive: boolean = true): string => { 35 | if (!startsWith(value, substr, 0, caseSensitive)) { 36 | return append(substr, value) 37 | } 38 | 39 | return value 40 | } 41 | -------------------------------------------------------------------------------- /src/ensureright.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import endsWith from './endswith' 3 | import append from './append' 4 | /** 5 | * @module ensureRight 6 | * @description 7 | * Ensures that the [value] ends with [substr]. If it doesn't, it's appended. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the ensureRight function 14 | * ```sh 15 | * yarn add strman.ensureright 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { ensureRight } from 'strman' 20 | * // OR 21 | * import ensureRight from 'strman.ensureright' 22 | * ``` 23 | * @param {String} value The input string 24 | * @param {String} substr The substr to be ensured to be right 25 | * @param {Boolean} [caseSensitive=true] 26 | * Use case (in-)sensitive matching for determining if `value` already ends with `substr` 27 | * @example 28 | * const value = 'Daniel' 29 | * const substr = ' Leite' 30 | * ensureRight(value, substr) 31 | * // => 'Daniel Leite' 32 | * @returns {String} The string which is guarenteed to start with `substr` 33 | */ 34 | export default (value: string, _substr: string, caseSensitive: boolean = true): string => { 35 | if (!endsWith(value, _substr, 0, caseSensitive)) { 36 | return append(value, _substr) 37 | } 38 | return value 39 | } 40 | -------------------------------------------------------------------------------- /src/equal.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module equal 4 | * @description 5 | * Tests if two strings are equal. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the equal function 12 | * ```sh 13 | * yarn add strman.equal 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { equal } from 'strman' 18 | * // OR 19 | * import equal from 'strman.equal' 20 | * ``` 21 | * @param {String} stringA - String for the comparative 22 | * @param {String} stringB - String to be compared 23 | * @example 24 | * equal('foo', 'foo') 25 | * // => true 26 | * @returns {Boolean} `stringA`is equal `stringB` 27 | */ 28 | export default (stringA: string, stringB: string) => stringA === stringB 29 | -------------------------------------------------------------------------------- /src/first.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import substr from './substr' 3 | /** 4 | * @module first 5 | * @description 6 | * Return the first 'n' chars of string. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the first function 13 | * ```sh 14 | * yarn add strman.first 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { first } from 'strman' 19 | * // OR 20 | * import first from 'strman.first' 21 | * ``` 22 | * @param {String} value - The String! 23 | * @param {Number} n - Number of chars to return. 24 | * @example 25 | * first('strman', 3) 26 | * // => 'str' 27 | * @returns {String} Return `n` firsts chars. 28 | */ 29 | export default (value: string, n: number): string => substr(value, 0, n) 30 | -------------------------------------------------------------------------------- /src/format.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import replace from './replace' 3 | 4 | /** 5 | * @module format 6 | * @description 7 | * Formats a string using parameters. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the format function 14 | * ```sh 15 | * yarn add strman.format 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { format } from 'strman' 20 | * // OR 21 | * import format from 'strman.format' 22 | * ``` 23 | * @param {String} value - Value that will be formatted. 24 | * @param {String[]} params - Array with the parameters described in the string. 25 | * @example 26 | * const select = `SELECT * FROM CONTACTS WHERE NAME LIKE '%{0}%' AND EMAIL LIKE '%{1}%'` 27 | * format(select, 'DANIEL', 'GMAIL') 28 | * // => `SELECT * FROM CONTACTS WHERE NAME LIKE '%DANIEL%' AND EMAIL LIKE '%GMAIL%'` 29 | * @returns {String} Formatted string. 30 | */ 31 | export default (value: string, params: Array = []) => 32 | replace(value, '{(\\w+)}', (match: string, index: number): string => { 33 | if (typeof params[index] !== 'undefined') { 34 | return params[index] 35 | } 36 | return match 37 | }) 38 | -------------------------------------------------------------------------------- /src/hexdecode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { LENGTH_HEXADECIMAL, BASE_HEXADECIMAL } from './lib/numericalbase' 3 | import decode from './lib/decode' 4 | 5 | /** 6 | * @module hexDecode 7 | * @description 8 | * Convert hexadecimal unicode (4 digits) string to string chars 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the hexDecode function 15 | * ```sh 16 | * yarn add strman.hexdecode 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { hexDecode } from 'strman' 21 | * // OR 22 | * import hexDecode from 'strman.hexdecode' 23 | * ``` 24 | * @param {String} value - Value to decode 25 | * @example 26 | * hexDecode('007300740072006d0061006e') 27 | * // => 'strman' 28 | * @returns {String} String decoded. 29 | */ 30 | export default (value: string): string => decode(value, LENGTH_HEXADECIMAL, BASE_HEXADECIMAL) 31 | -------------------------------------------------------------------------------- /src/hexencode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { LENGTH_HEXADECIMAL, BASE_HEXADECIMAL } from './lib/numericalbase' 3 | import encode from './lib/encode' 4 | /** 5 | * @module hexEncode 6 | * @description 7 | * Convert string chars to hexadecimal unicode (4 digits) 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the hexEncode function 14 | * ```sh 15 | * yarn add strman.hexencode 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { hexEncode } from 'strman' 20 | * // OR 21 | * import hexEncode from 'strman.hexencode' 22 | * ``` 23 | * @param {String} value - Value to encode 24 | * @example 25 | * hexEncode('strman') 26 | * // => '007300740072006d0061006e' 27 | * @returns {String} String in hexadecimal format. 28 | */ 29 | export default (value: string): string => encode(value, LENGTH_HEXADECIMAL, BASE_HEXADECIMAL) 30 | -------------------------------------------------------------------------------- /src/htmldecode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import entitiesDecode from './lib/entitiesdecode' 3 | import replace from './replace' 4 | /** 5 | * @module htmlDecode 6 | * @description 7 | * Convert all HTML entities to applicable characters. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the htmlDecode function 14 | * ```sh 15 | * yarn add strman.htmldecode 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { htmlDecode } from 'strman' 20 | * // OR 21 | * import htmlDecode from 'strman.htmldecode' 22 | * ``` 23 | * @param {String} value - value to decode. 24 | * @example 25 | * htmlDecode('<div>') 26 | * // => '
' 27 | * @returns { String } The decoded data. 28 | */ 29 | export default (value: string): string => 30 | replace(value, '(&\\w+;)', (match: string, index: number): string => { 31 | if (typeof entitiesDecode[index] !== 'undefined') { 32 | return entitiesDecode[index] 33 | } 34 | return match 35 | }) 36 | -------------------------------------------------------------------------------- /src/htmlencode.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import entitiesEncode from './lib/entitiesencode' 3 | import replace from './replace' 4 | /** 5 | * @module htmlEncode 6 | * @description 7 | * Convert all applicable characters to HTML entities. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the htmlEncode function 14 | * ```sh 15 | * yarn add strman.htmlencode 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { htmlEncode } from 'strman' 20 | * // OR 21 | * import htmlEncode from 'strman.htmlencode' 22 | * ``` 23 | * @param {String} value value to encode. 24 | * @example 25 | * htmlEncode('
') 26 | * // => '<div>' 27 | * @returns { String } The encoded data. 28 | */ 29 | export default (value: string): string => 30 | replace( 31 | value, 32 | '[\\u00A0-\\u9999<>\\&]', 33 | (match: string): string => { 34 | if (typeof entitiesEncode[match] !== 'undefined') { 35 | return entitiesEncode[match] 36 | } 37 | return match 38 | }, 39 | true, 40 | true, 41 | ) 42 | -------------------------------------------------------------------------------- /src/indexof.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toCaseSensitive from './lib/case' 3 | /** 4 | * @module inequal 5 | * @description 6 | * The indexOf() method returns the index within the calling String of the first occurrence 7 | * of the specified value, starting the search at fromIndex. Returns -1 if the value is not found. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the inequal function 14 | * ```sh 15 | * yarn add strman.inequal 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { inequal } from 'strman' 20 | * // OR 21 | * import inequal from 'strman.inequal' 22 | * ``` 23 | * @param {String} value The String! 24 | * @param {String} needle Value to search. 25 | * @param {Number} [offset = 0] Offset to search. 26 | * @param {Boolean} [caseSensitive = true] if you use caseSensitive to test. 27 | * @example 28 | * indexOf('strman', 'man') 29 | * // => 3 30 | * @returns {Number} Return position of the first occurrence of 'needle'. 31 | */ 32 | export default ( 33 | value: string, 34 | needle: string, 35 | offset: number = 0, 36 | caseSensitive: boolean = true, 37 | ): number => 38 | toCaseSensitive(value, caseSensitive).indexOf(toCaseSensitive(needle, caseSensitive), offset) 39 | -------------------------------------------------------------------------------- /src/inequal.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module inequal 4 | * @description 5 | * Tests if two strings are inequal. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the inequal function 12 | * ```sh 13 | * yarn add strman.inequal 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { inequal } from 'strman' 18 | * // OR 19 | * import inequal from 'strman.inequal' 20 | * ``` 21 | * @param {String} stringA - String for the comparative 22 | * @param {String} stringB - String to be compared 23 | * @example 24 | * inequal('foo', 'foo') 25 | * // => false 26 | * @returns {Boolean} [stringA] is inequal [stringB] 27 | */ 28 | export default (stringA: string, stringB: string): boolean => stringA !== stringB 29 | -------------------------------------------------------------------------------- /src/insert.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import _substr from './substr' 3 | import append from './append' 4 | /** 5 | * @module insert 6 | * @description 7 | * Inserts 'substr' into the 'value' at the 'index' provided. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the insert function 14 | * ```sh 15 | * yarn add strman.insert 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { insert } from 'strman' 20 | * // OR 21 | * import insert from 'strman.insert' 22 | * ``` 23 | * @param {String} value The String! 24 | * @param {String} substr Value to insert. 25 | * @param {Number} index Index to insert substr. 26 | * @example 27 | * const title = "trman" 28 | * insert(title, 's', 0) 29 | * // => 'strman' 30 | * @returns {String} String with substr added. 31 | */ 32 | export default (value: string, substr: string, index: number): string => { 33 | if (index > value.length) { 34 | return value 35 | } 36 | 37 | const start = _substr(value, 0, index) 38 | const end = _substr(value, index, value.length) 39 | 40 | return append(start, substr, end) 41 | } 42 | -------------------------------------------------------------------------------- /src/islowercase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toLowerCase from './tolowercase' 3 | /** 4 | * @module isLowerCase 5 | * @description 6 | * Verify if has lowerCase 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the isLowerCase function 13 | * ```sh 14 | * yarn add strman.islowercase 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { isLowerCase } from 'strman' 19 | * // OR 20 | * import isLowerCase from 'strman.islowercase' 21 | * ``` 22 | * @param {String} value - The String! 23 | * @playground 24 | * const title = 'A Javascript string manipulation library.' 25 | * isLowerCase(title) 26 | * // => false 27 | * @returns {Boolean} String is lowercase? 28 | */ 29 | export default (value: string): boolean => value === toLowerCase(value) 30 | -------------------------------------------------------------------------------- /src/isstring.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module isString 4 | * @description 5 | * Checks whether a string. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the isString function 12 | * ```sh 13 | * yarn add strman.isstring 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { isString } from 'strman' 18 | * // OR 19 | * import isString from 'strman.isstring' 20 | * ``` 21 | * @param {String} value The String! 22 | * @example 23 | * const title = 'A Javascript string manipulation library.' 24 | * isString(title) 25 | * // => true 26 | * @returns {Boolean} if 'value' isString, return true, else false. 27 | */ 28 | export default (value: string): boolean => 29 | Object.prototype.toString.call(value) === '[object String]' 30 | -------------------------------------------------------------------------------- /src/isuppercase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toUpperCase from './touppercase' 3 | /** 4 | * @module isUpperCase 5 | * @description 6 | * Verify if has UPPERCASE 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the isUpperCase function 13 | * ```sh 14 | * yarn add strman.isuppercase 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { isUpperCase } from 'strman' 19 | * // OR 20 | * import isUpperCase from 'strman.isuppercase' 21 | * ``` 22 | * @param {String} value The String! 23 | * @example 24 | * const title = 'A Javascript string manipulation library.' 25 | * isUpperCase(title) 26 | * // => false 27 | * @returns {Boolean} String is UPPERCASE?. 28 | */ 29 | export default (value: string): boolean => value === toUpperCase(value) 30 | -------------------------------------------------------------------------------- /src/last.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import substr from './substr' 3 | /** 4 | * @module last 5 | * @description 6 | * Return the last 'n' chars of string. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the last function 13 | * ```sh 14 | * yarn add strman.last 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { last } from 'strman' 19 | * // OR 20 | * import last from 'strman.last' 21 | * ``` 22 | * @param {String} value The String! 23 | * @param {Number} n Number of chars to return. 24 | * @example 25 | * const title = 'strman' 26 | * last(title, 3) 27 | * // => 'man' 28 | * @returns {String} Return 'n' lasts chars. 29 | */ 30 | export default (value: string, n: number): string => substr(value, -1 * n, n) 31 | -------------------------------------------------------------------------------- /src/lastindexof.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toCaseSensitive from './lib/case' 3 | /** 4 | * @module lastIndefOf 5 | * @description 6 | * The lastIndexOf() method returns the index within the calling String object of the last 7 | * occurrence of the specified value, searching backwards from fromIndex. Returns -1 if the 8 | * value is not found. 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the lastIndefOf function 15 | * ```sh 16 | * yarn add strman.lastindexof 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { lastIndefOf } from 'strman' 21 | * // OR 22 | * import lastIndefOf from 'strman.lastindexof' 23 | * ``` 24 | * @param {String} value The String! 25 | * @param {String} needle Value to search. 26 | * @param {Number} [offset = undefined] Offset to search. 27 | * @param {Boolean} [caseSensitive = true] if you use caseSensitive to test. 28 | * @example 29 | * const title = 'strman strman' 30 | * result = lastIndexOf(title, 'str') 31 | * // => 7 32 | * @returns {Number} Return position of the last occurrence of 'needle'. 33 | */ 34 | export default ( 35 | value: string, 36 | needle: string, 37 | offset: ?number = undefined, 38 | caseSensitive: boolean = true, 39 | ): number => 40 | toCaseSensitive(value, caseSensitive).lastIndexOf(toCaseSensitive(needle, caseSensitive), offset) 41 | -------------------------------------------------------------------------------- /src/leftpad.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import substr from './substr' 3 | import append from './append' 4 | import repeat from './repeat' 5 | /** 6 | * @module leftPad 7 | * @description 8 | * Returns a new string of a given length such that the beginning of the string is padded. 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the leftPad function 15 | * ```sh 16 | * yarn add strman.leftpad 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { leftPad } from 'strman' 21 | * // OR 22 | * import leftPad from 'strman.leftpad' 23 | * ``` 24 | * @param {String} value - The String! 25 | * @param {Number} length - Max length of String. 26 | * @param {Char} [char = ' '] - Char to repeat. 27 | * @example 28 | * const title = 'strman' 29 | * leftPad(title, 10, 0) 30 | * // => '0000strman' 31 | * @returns {String} String pad. 32 | */ 33 | export default (value: string, length: number, char: string = ' '): string => { 34 | let result = value 35 | let newchar = String(char) 36 | 37 | if (newchar.length > 1) { 38 | newchar = substr(newchar, 0, 1) 39 | } 40 | 41 | const newlength = length - value.length 42 | result = append(repeat(newchar, newlength), result) 43 | 44 | return result 45 | } 46 | -------------------------------------------------------------------------------- /src/lefttrim.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import replace from './replace' 3 | /** 4 | * @module leftTrim 5 | * @description 6 | * Remove all spaces on left. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the leftTrim function 13 | * ```sh 14 | * yarn add strman.lefttrim 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { leftTrim } from 'strman' 19 | * // OR 20 | * import leftTrim from 'strman.lefttrim' 21 | * ``` 22 | * @param {String} value The String! 23 | * @param {String} [char = ''] if you need remove other char on left boarders. 24 | * @example 25 | * const title = ' strman' 26 | * leftTrim(title) 27 | * // => 'strman' 28 | * @returns {String} String without left boarders spaces. 29 | */ 30 | export default (value: string, char: string = ' '): string => replace(value, `^${char}+`, '') 31 | -------------------------------------------------------------------------------- /src/lib/ascii.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Credits for: @danielstjules 3 | * https://github.com/danielstjules/Stringy/blob/master/src/Stringy.php#L1601-L1756 4 | */ 5 | export default { 6 | 0: ['°', '₀', '۰'], 7 | 1: ['¹', '₁', '۱'], 8 | 2: ['²', '₂', '۲'], 9 | 3: ['³', '₃', '۳'], 10 | 4: ['⁴', '₄', '۴', '٤'], 11 | 5: ['⁵', '₅', '۵', '٥'], 12 | 6: ['⁶', '₆', '۶', '٦'], 13 | 7: ['⁷', '₇', '۷'], 14 | 8: ['⁸', '₈', '۸'], 15 | 9: ['⁹', '₉', '۹'], 16 | a: ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 17 | 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 18 | 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 19 | 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], 20 | b: ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], 21 | c: ['ç', 'ć', 'č', 'ĉ', 'ċ'], 22 | d: ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], 23 | e: ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 24 | 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 25 | 'ဲ', 'ე', 'ए', 'إ', 'ئ'], 26 | f: ['ф', 'φ', 'ف', 'ƒ', 'ფ'], 27 | g: ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], 28 | h: ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], 29 | i: ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 30 | 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 31 | 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ', 'ی'], 32 | j: ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], 33 | k: ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], 34 | l: ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], 35 | m: ['м', 'μ', 'م', 'မ', 'მ'], 36 | n: ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], 37 | o: ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 38 | 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 39 | 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], 40 | p: ['п', 'π', 'ပ', 'პ', 'پ'], 41 | q: ['ყ'], 42 | r: ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], 43 | s: ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], 44 | t: ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], 45 | u: ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 46 | 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], 47 | v: ['в', 'ვ', 'ϐ'], 48 | w: ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], 49 | x: ['χ', 'ξ'], 50 | y: ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], 51 | z: ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], 52 | aa: ['ع', 'आ', 'آ'], 53 | ae: ['ä', 'æ', 'ǽ'], 54 | ai: ['ऐ'], 55 | at: ['@'], 56 | ch: ['ч', 'ჩ', 'ჭ', 'چ'], 57 | dj: ['ђ', 'đ'], 58 | dz: ['џ', 'ძ'], 59 | ei: ['ऍ'], 60 | gh: ['غ', 'ღ'], 61 | ii: ['ई'], 62 | ij: ['ij'], 63 | kh: ['х', 'خ', 'ხ'], 64 | lj: ['љ'], 65 | nj: ['њ'], 66 | oe: ['ö', 'œ', 'ؤ'], 67 | oi: ['ऑ'], 68 | oii: ['ऒ'], 69 | ps: ['ψ'], 70 | sh: ['ш', 'შ', 'ش'], 71 | shch: ['щ'], 72 | ss: ['ß'], 73 | sx: ['ŝ'], 74 | th: ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], 75 | ts: ['ц', 'ც', 'წ'], 76 | ue: ['ü'], 77 | uu: ['ऊ'], 78 | ya: ['я'], 79 | yu: ['ю'], 80 | zh: ['ж', 'ჟ', 'ژ'], 81 | '(c)': ['©'], 82 | A: ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 83 | 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 84 | 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'], 85 | B: ['Б', 'Β', 'ब'], 86 | C: ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'], 87 | D: ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'], 88 | E: ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 89 | 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə'], 90 | F: ['Ф', 'Φ'], 91 | G: ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'], 92 | H: ['Η', 'Ή', 'Ħ'], 93 | I: ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 94 | 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'], 95 | K: ['К', 'Κ'], 96 | L: ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'], 97 | M: ['М', 'Μ'], 98 | N: ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'], 99 | O: ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 100 | 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'], 101 | P: ['П', 'Π'], 102 | R: ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'], 103 | S: ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'], 104 | T: ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'], 105 | U: ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 106 | 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ'], 107 | V: ['В'], 108 | W: ['Ω', 'Ώ', 'Ŵ'], 109 | X: ['Χ', 'Ξ'], 110 | Y: ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], 111 | Z: ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], 112 | AE: ['Ä', 'Æ', 'Ǽ'], 113 | CH: ['Ч'], 114 | DJ: ['Ђ'], 115 | DZ: ['Џ'], 116 | GX: ['Ĝ'], 117 | HX: ['Ĥ'], 118 | IJ: ['IJ'], 119 | JX: ['Ĵ'], 120 | KH: ['Х'], 121 | LJ: ['Љ'], 122 | NJ: ['Њ'], 123 | OE: ['Ö', 'Œ'], 124 | PS: ['Ψ'], 125 | SH: ['Ш'], 126 | SHCH: ['Щ'], 127 | SS: ['ẞ'], 128 | TH: ['Þ'], 129 | TS: ['Ц'], 130 | UE: ['Ü'], 131 | YA: ['Я'], 132 | YU: ['Ю'], 133 | ZH: ['Ж'], 134 | ' ': ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", // eslint-disable-line 135 | "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", // eslint-disable-line 136 | "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"] // eslint-disable-line 137 | } 138 | -------------------------------------------------------------------------------- /src/lib/case.js: -------------------------------------------------------------------------------- 1 | import toUpperCase from '../touppercase' 2 | 3 | export default (value, caseSensitive = true) => { 4 | if (caseSensitive) { 5 | return value 6 | } 7 | return toUpperCase(value) 8 | } 9 | -------------------------------------------------------------------------------- /src/lib/decode.js: -------------------------------------------------------------------------------- 1 | export default (value, length, base) => 2 | value.match(new RegExp(`.{1,${length}}`, 'g')) 3 | .map(string => String.fromCharCode(parseInt(string, base))).join('') 4 | -------------------------------------------------------------------------------- /src/lib/encode.js: -------------------------------------------------------------------------------- 1 | import chars from '../chars' 2 | import leftPad from '../leftpad' 3 | 4 | export default (value, length, base) => 5 | chars(value).map(data => leftPad(data.charCodeAt(0).toString(base), length, '0')).join('') 6 | -------------------------------------------------------------------------------- /src/lib/numericalbase.js: -------------------------------------------------------------------------------- 1 | export const BASE_HEXADECIMAL = 16 2 | export const LENGTH_HEXADECIMAL = 4 3 | 4 | export const BASE_BINARY = 2 5 | export const LENGTH_BINARY = 16 6 | 7 | export const BASE_DECIMAL = 10 8 | export const LENGTH_DECIMAL = 5 9 | -------------------------------------------------------------------------------- /src/lib/poparray.js: -------------------------------------------------------------------------------- 1 | export default array => array.slice(0, -1) 2 | -------------------------------------------------------------------------------- /src/prepend.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import prependArray from './prependarray' 3 | /** 4 | * @module prepend 5 | * @description 6 | * Returns a new string starting with 'prepends'. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the prepend function 13 | * ```sh 14 | * yarn add strman.prepend 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { prepend } from 'strman' 19 | * // OR 20 | * import prepend from 'strman.prepend' 21 | * ``` 22 | * @param {String} value - The String! 23 | * @param {...String} prepends - Strings to prepend. 24 | * @example 25 | * const title = 'strman' 26 | * prepend(title, '_') 27 | * // => '_strman' 28 | * @returns {String} The String prepended! 29 | */ 30 | export default (value: string, ...prepends: Array): string => prependArray(value, prepends) 31 | -------------------------------------------------------------------------------- /src/prependarray.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module prependArray 4 | * @description 5 | * Returns a new string starting with 'prepends'. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the prependArray function 12 | * ```sh 13 | * yarn add strman.prependarray 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { prependArray } from 'strman' 18 | * // OR 19 | * import prependArray from 'strman.prependarray' 20 | * ``` 21 | * @param {String} value The String! 22 | * @param {String[]} prepends Strings to prepend. 23 | * @example 24 | * const title = 'strman' 25 | * prependArray(title, ['_']) 26 | * // => '_strman' 27 | * @returns {String} The String prepended! 28 | */ 29 | export default (value: string, prepends: Array = []): string => { 30 | if (prepends.length === 0) { 31 | return value 32 | } 33 | return prepends.join('') + value 34 | } 35 | -------------------------------------------------------------------------------- /src/removeemptystrings.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module removeEmptyStrings 4 | * @description 5 | * Remove empty strings from strings array. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the removeEmptyStrings function 12 | * ```sh 13 | * yarn add strman.removeemptystrings 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { removeEmptyStrings } from 'strman' 18 | * // OR 19 | * import removeEmptyStrings from 'strman.removeemptystrings' 20 | * ``` 21 | * @param {String[]} strings - Array of strings that will be cleaned. 22 | * @example 23 | * const titles = ['A Javascript string manipulation library.', null, undefined, '', ' '] 24 | * removeEmptyStrings(titles) 25 | * // => ['A Javascript string manipulation library.'] 26 | * @returns {String[]} Array of strings without empty strings. 27 | */ 28 | export default (strings: Array): Array => 29 | strings.filter(string => string && string !== '') 30 | -------------------------------------------------------------------------------- /src/removeleft.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import startsWith from './startswith' 3 | import substr from './substr' 4 | /** 5 | * @module removeLeft 6 | * @description 7 | * Returns a new string with the 'prefix' removed, if present. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the removeLeft function 14 | * ```sh 15 | * yarn add strman.removeleft 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { removeLeft } from 'strman' 20 | * // OR 21 | * import removeLeft from 'strman.removeleft' 22 | * ``` 23 | * @param {String} value The String! 24 | * @param {String} prefix String to remove on left. 25 | * @param {Boolean} [caseSensitive = true] If you need to caseSensitive. 26 | * @example 27 | * const title = 'strman' 28 | * removeLeft(title, 'str') 29 | * // => 'man' 30 | * @returns {String} The String without prefix! 31 | */ 32 | export default (value: string, prefix: string, caseSensitive: boolean = true): string => { 33 | if (startsWith(value, prefix, 0, caseSensitive)) { 34 | return substr(value, prefix.length) 35 | } 36 | return value 37 | } 38 | -------------------------------------------------------------------------------- /src/removenonwords.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import replace from './replace' 3 | /** 4 | * @module removeNonWords 5 | * @description 6 | * Remove all non word characters. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the removeNonWords function 13 | * ```sh 14 | * yarn add strman.removenowords 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { removeNonWords } from 'strman' 19 | * // OR 20 | * import removeNonWords from 'strman.removenowords' 21 | * ``` 22 | * @param {String} value The String! 23 | * @param {String} [replaced = ''] Value to replace. 24 | * @example 25 | * const title = '__strman../' 26 | * removeNonWords(title) 27 | * // => 'strman' 28 | * @returns {String} String without non word characters. 29 | */ 30 | export default (value: string, replaced: string = ''): string => replace(value, '[^\\w]+', replaced) 31 | -------------------------------------------------------------------------------- /src/removeright.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import endsWith from './endswith' 3 | import substr from './substr' 4 | /** 5 | * @module removeSpaces 6 | * @description 7 | * Returns a new string with the 'suffix' removed, if present. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the removeSpaces function 14 | * ```sh 15 | * yarn add strman.removespaces 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { removeSpaces } from 'strman' 20 | * // OR 21 | * import removeSpaces from 'strman.removespaces' 22 | * ``` 23 | * @param {String} value The String! 24 | * @param {String} suffix String to remove on right. 25 | * @param {Boolean} [caseSensitive = true] If you need to caseSensitive. 26 | * @example 27 | * const title = 'strman' 28 | * removeRight(title, 'man') 29 | * // => 'str' 30 | * @returns {String} The String without suffix! 31 | */ 32 | export default (value: string, suffix: string, caseSensitive: boolean = true): string => { 33 | if (endsWith(value, suffix, null, caseSensitive)) { 34 | const length = value.length - suffix.length 35 | return substr(value, 0, length) 36 | } 37 | 38 | return value 39 | } 40 | -------------------------------------------------------------------------------- /src/removespaces.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import replace from './replace' 3 | 4 | /** 5 | * @module removeSpaces 6 | * @description 7 | * Remove all spaces and replace for value. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the removeSpaces function 14 | * ```sh 15 | * yarn add strman.removespaces 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { removeSpaces } from 'strman' 20 | * // OR 21 | * import removeSpaces from 'strman.removespaces' 22 | * ``` 23 | * @param {String} value - The String! 24 | * @param {String} replaced - Value to replace. 25 | * @example 26 | * const title = ' s t r m a n ' 27 | * removeSpaces(title) 28 | * // => 'strman' 29 | * @returns {String} String without spaces. 30 | */ 31 | export default (value: string, replaced: string = ''): string => replace(value, '\\s+', replaced) 32 | -------------------------------------------------------------------------------- /src/repeat.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module repeat 4 | * @description 5 | * Returns a repeated string given a multiplier. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the repeat function 12 | * ```sh 13 | * yarn add strman.repeat 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { repeat } from 'strman' 18 | * // OR 19 | * import repeat from 'strman.repeat' 20 | * ``` 21 | * @param {String} value - The String! 22 | * @param {Number} multiplier - Number of repeats. 23 | * @example 24 | * const title = 'strman' 25 | * repeat(title, 5) 26 | * // => 'strmanstrmanstrmanstrmanstrman' 27 | * @returns {String} The String repeated! 28 | */ 29 | export default (value: string, multiplier: number): string => { 30 | let i = 0 31 | let result = '' 32 | while (multiplier > i) { 33 | result += value 34 | i += 1 35 | } 36 | return result 37 | } 38 | -------------------------------------------------------------------------------- /src/replace.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module replace 4 | * @description 5 | * Replace all ocurrences of 'search' value to 'newvalue'. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the replace function 12 | * ```sh 13 | * yarn add strman.replace 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { replace } from 'strman' 18 | * // OR 19 | * import replace from 'strman.replace' 20 | * ``` 21 | * @param {String} value The String! 22 | * @param {String} search String to search. 23 | * @param {String} newvalue String to replace. 24 | * @param {Boolean} caseSensitive if you use caseSensitive replace. 25 | * @param {Boolean} multiline if you use multiline replace. 26 | * @example 27 | * const title = 'superman' 28 | * replace(title, 'upe', 't') 29 | * // => 'strman' 30 | * @returns {String} String replaced with 'newvalue'. 31 | */ 32 | export default ( 33 | value: string, 34 | search: string = '', 35 | newvalue: string | Function = '', 36 | caseSensitive: boolean = true, 37 | multiline: boolean = true, 38 | ): string => { 39 | const flags = caseSensitive ? 'g' : 'gi' 40 | const flagsMultiline = multiline ? `${flags}m` : flags 41 | 42 | return value.replace(new RegExp(search, flagsMultiline), newvalue) 43 | } 44 | -------------------------------------------------------------------------------- /src/reverse.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import split from './split' 3 | import append from './append' 4 | /** 5 | * @module reverse 6 | * @description 7 | * Returns a reversed string. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the reverse function 14 | * ```sh 15 | * yarn add strman.reverse 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { reverse } from 'strman' 20 | * // OR 21 | * import reverse from 'strman.reverse' 22 | * ``` 23 | * @param {String} value - The String! 24 | * @example 25 | * reverse('strman') 26 | * // => 'namrts' 27 | * @returns {String} The String reversed! 28 | */ 29 | export default (value: string): string => 30 | split(value, '').reduceRight((previous, current) => append(previous, current), '') 31 | -------------------------------------------------------------------------------- /src/rightpad.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import substr from './substr' 3 | import append from './append' 4 | 5 | const rightPad = (value: string, length: number, char: string): string => { 6 | if (value.length === length) { 7 | return value 8 | } 9 | return rightPad(append(value, char), length, char) 10 | } 11 | 12 | /** 13 | * @module rightPad 14 | * @description 15 | * Returns a new string of a given length such that the ending of the string is padded. 16 | * ## Install 17 | * Install all functions of strman 18 | * ```sh 19 | * yarn add strman 20 | * ``` 21 | * or just the rightPad function 22 | * ```sh 23 | * yarn add strman.rightpad 24 | * ``` 25 | * ## Usage 26 | * ```javascript 27 | * import { rightPad } from 'strman' 28 | * // OR 29 | * import rightPad from 'strman.rightpad' 30 | * ``` 31 | * @param {String} value The String! 32 | * @param {Number} _length Max length of String. 33 | * @param {Char} char Char to repeat. 34 | * @example 35 | * const title = "strman" 36 | * rightPad(title, 10, 0) 37 | * // => 'strman0000' 38 | * @returns {String} String pad. 39 | */ 40 | export default (value: string, length: number, char: string = ' '): string => 41 | rightPad(value, length, substr(String(char), 0, 1)) 42 | -------------------------------------------------------------------------------- /src/righttrim.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import replace from './replace' 3 | 4 | /** 5 | * @module rightTrim 6 | * @description 7 | * Remove all spaces on right. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the rightTrim function 14 | * ```sh 15 | * yarn add strman.righttrim 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { rightTrim } from 'strman' 20 | * // OR 21 | * import rightTrim from 'strman.righttrim' 22 | * ``` 23 | * @param {String} value The String! 24 | * @param {String} [char = ' '] if you need remove other char on right boarders. 25 | * @example 26 | * const title = 'strman ' 27 | * rightTrim(title) 28 | * // => 'strman' 29 | * @returns {String} String without right boarders spaces. 30 | */ 31 | export default (value: string, char: string = ' '): string => replace(value, `${char}+$`, '') 32 | -------------------------------------------------------------------------------- /src/safetruncate.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import _append from './append' 3 | import lastIndexOf from './lastindexof' 4 | import indexOf from './indexof' 5 | import substr from './substr' 6 | 7 | /** 8 | * @module safeTruncate 9 | * @description 10 | * Truncate the string securely, not cutting a word in half. It always returns the last full word. 11 | * ## Install 12 | * Install all functions of strman 13 | * ```sh 14 | * yarn add strman 15 | * ``` 16 | * or just the safeTruncate function 17 | * ```sh 18 | * yarn add strman.safetruncate 19 | * ``` 20 | * ## Usage 21 | * ```javascript 22 | * import { safeTruncate } from 'strman' 23 | * // OR 24 | * import safeTruncate from 'strman.safetruncate' 25 | * ``` 26 | * @param {String} value Value will be truncated securely. 27 | * @param {Number} length Max size of the returned string. 28 | * @param {String} [append = ''] Value that will be added to the end of the return string. 29 | * @example 30 | * const title = 'A Javascript string manipulation library.' 31 | * safeTruncate(title, 15, '...'); 32 | * // => 'A Javascript...' 33 | * @returns {String} String truncated safely. 34 | */ 35 | export default (value: string, length: number, append: string = ''): string => { 36 | let truncated = '' 37 | 38 | if (length === 0) { 39 | return '' 40 | } 41 | 42 | if (length >= value.length) { 43 | return value 44 | } 45 | 46 | const newLength = length - append.length 47 | truncated = substr(value, 0, newLength) 48 | 49 | const position = indexOf(value, ' ', newLength - 1) 50 | 51 | if (position !== newLength) { 52 | const lastPos = lastIndexOf(truncated, ' ') 53 | truncated = substr(truncated, 0, lastPos) 54 | } 55 | 56 | return _append(truncated, append) 57 | } 58 | -------------------------------------------------------------------------------- /src/shuffle.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import split from './split' 3 | 4 | const shuffle = (array: Array = []): Array => { 5 | let j 6 | let i 7 | const newArray = array 8 | for (i = array.length; i; i -= 1) { 9 | j = Math.floor(Math.random() * i) 10 | newArray[i - 1] = array[j] 11 | newArray[j] = array[i - 1] 12 | } 13 | return newArray 14 | } 15 | 16 | /** 17 | * @module shuffle 18 | * @description 19 | * It returns a string with its characters in random order. 20 | * ## Install 21 | * Install all functions of strman 22 | * ```sh 23 | * yarn add strman 24 | * ``` 25 | * or just the shuffle function 26 | * ```sh 27 | * yarn add strman.shuffle 28 | * ``` 29 | * ## Usage 30 | * ```javascript 31 | * import { shuffle } from 'strman' 32 | * // OR 33 | * import shuffle from 'strman.shuffle' 34 | * ``` 35 | * @param {String} value The String! 36 | * @example 37 | * shuffle('strman') 38 | * // => 'rtmnas' 39 | * @returns {String} The String shuffled! 40 | */ 41 | export default (value: string): string => shuffle(split(value)).join('') 42 | -------------------------------------------------------------------------------- /src/slice.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module slugify 4 | * @description 5 | * Alias to slice method. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the slugify function 12 | * ```sh 13 | * yarn add strman.slugify 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { slugify } from 'strman' 18 | * // OR 19 | * import slugify from 'strman.slugify' 20 | * ``` 21 | * @param {String} value The String! 22 | * @param {Number} beginSlice Start of slice. 23 | * @param {Number} endSlice End of slice. 24 | * @example 25 | * const title = 'strman' 26 | * slice(title, 2, 5) 27 | * // => 'rma' 28 | * @returns {String} The String sliced! 29 | */ 30 | export default (value: string, beginSlice: number, endSlice: number = beginSlice): string => 31 | value.slice(beginSlice, endSlice) 32 | -------------------------------------------------------------------------------- /src/slugify.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toLowerCase from './tolowercase' 3 | import trim from './trim' 4 | import removeSpaces from './removespaces' 5 | import replace from './replace' 6 | import transliterate from './transliterate' 7 | /** 8 | * @module slugify 9 | * @description 10 | * Converts a value to a slug. 11 | * ## Install 12 | * Install all functions of strman 13 | * ```sh 14 | * yarn add strman 15 | * ``` 16 | * or just the slugify function 17 | * ```sh 18 | * yarn add strman.slugify 19 | * ``` 20 | * ## Usage 21 | * ```javascript 22 | * import { slugify } from 'strman' 23 | * // OR 24 | * import slugify from 'strman.slugify' 25 | * ``` 26 | * @param {String} value The value to slugify 27 | * @example 28 | * const title = 'A Javascript string manipulation library.' 29 | * slugify(title) 30 | * // => 'a-javascript-string-manipulation-library' 31 | * @returns {String} The slugified value 32 | */ 33 | export default (value: string): string => { 34 | const lowerCaseValue = toLowerCase(value) 35 | const trimValue = trim(lowerCaseValue) 36 | const valueWithoutSpaces = removeSpaces(trimValue, '-') 37 | const valueWithE = replace(valueWithoutSpaces, '&', '-and-') 38 | const transliterateValue = transliterate(valueWithE) 39 | const wordsOnlyValue = replace(transliterateValue, '[^\\w\\-]+', '') 40 | const singleDashesValue = replace(wordsOnlyValue, '-+', '-') 41 | return trim(singleDashesValue, '-') 42 | } 43 | -------------------------------------------------------------------------------- /src/split.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module split 4 | * @description 5 | * Alias to split function. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the split function 12 | * ```sh 13 | * yarn add strman.split 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { split } from 'strman' 18 | * // OR 19 | * import split from 'strman.split' 20 | * ``` 21 | * @param {String} value - The String! 22 | * @param {String} separator - Split separator. 23 | * @param {Number} limit - Split limit. 24 | * @example 25 | * split('strman', '') 26 | * // => ['s', 't', 'r', 'm', 'a', 'n'] 27 | * @returns {String} The String splited! 28 | */ 29 | export default (value: string, separator: string = '', limit: number = -1): Array => 30 | value.split(separator, limit) 31 | -------------------------------------------------------------------------------- /src/startswith.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import substr from './substr' 3 | import toCaseSensitive from './lib/case' 4 | /** 5 | * @module startsWith 6 | * @description 7 | * Test if 'value' starts with 'search' 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the startsWith function 14 | * ```sh 15 | * yarn add strman.startswith 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { startsWith } from 'strman' 20 | * // OR 21 | * import startsWith from 'strman.startswith' 22 | * ``` 23 | * @param {String} value The String! 24 | * @param {String} search Value to search. 25 | * @param {Number} [position = 0] offset to search. 26 | * @param {Boolean} [caseSensitive = true] if you use caseSensitive to test. 27 | * @example 28 | * startsWith('strman', 'str') 29 | * // => true 30 | * @returns {Boolean} If 'value' startsWith 'search' return true, else false. 31 | */ 32 | export default ( 33 | value: string, 34 | search: string, 35 | position: number = 0, 36 | caseSensitive: boolean = true, 37 | ): boolean => 38 | substr(toCaseSensitive(value, caseSensitive), position, search.length) === 39 | toCaseSensitive(search, caseSensitive) 40 | -------------------------------------------------------------------------------- /src/strman.js: -------------------------------------------------------------------------------- 1 | export chars from './chars' 2 | export ensureLeft from './ensureleft' 3 | export inequal from './inequal' 4 | export prepend from './prepend' 5 | export rightPad from './rightpad' 6 | export surround from './surround' 7 | export truncate from './truncate' 8 | export collapseWhitespace from './collapsewhitespace' 9 | export ensureRight from './ensureright' 10 | export insert from './insert' 11 | export prependArray from './prependarray' 12 | export rightTrim from './righttrim' 13 | export toCamelCase from './tocamelcase' 14 | export urlDecode from './urlDecode' 15 | export append from './append' 16 | export compare from './compare' 17 | export equal from './equal' 18 | export isLowerCase from './islowercase' 19 | export removeEmptyStrings from './removeemptystrings' 20 | export safeTruncate from './safetruncate' 21 | export toDecamelize from './todecamelize' 22 | export urlEncode from './urlencode' 23 | export appendArray from './appendarray' 24 | export contains from './contains' 25 | export first from './first' 26 | export isString from './isstring' 27 | export removeLeft from './removeleft' 28 | export shuffle from './shuffle' 29 | export toKebabCase from './tokebabcase' 30 | export at from './at' 31 | export containsAll from './containsall' 32 | export format from './format' 33 | export isUpperCase from './isuppercase' 34 | export removeNonWords from './removenonwords' 35 | export slice from './slice' 36 | export toLowerCase from './tolowercase' 37 | export base64decode from './base64decode' 38 | export containsAny from './containsany' 39 | export hexDecode from './hexdecode' 40 | export last from './last' 41 | export removeRight from './removeright' 42 | export slugify from './slugify' 43 | export toSnakeCase from './tosnakecase' 44 | export base64encode from './base64encode' 45 | export countSubstr from './countsubstr' 46 | export hexEncode from './hexencode' 47 | export lastIndexOf from './lastindexof' 48 | export removeSpaces from './removespaces' 49 | export split from './split' 50 | export toStudlyCaps from './tostudlycaps' 51 | export between from './between' 52 | export decDecode from './decdecode' 53 | export htmlDecode from './htmldecode' 54 | export leftPad from './leftpad' 55 | export repeat from './repeat' 56 | export startsWith from './startswith' 57 | export toUpperCase from './touppercase' 58 | export binDecode from './bindecode' 59 | export decEncode from './decencode' 60 | export htmlEncode from './htmlencode' 61 | export leftTrim from './lefttrim' 62 | export replace from './replace' 63 | export transliterate from './transliterate' 64 | export binEncode from './binencode' 65 | export endsWith from './endswith' 66 | export indexOf from './indexof' 67 | export reverse from './reverse' 68 | export substr from './substr' 69 | export trim from './trim' 70 | 71 | export default exports 72 | -------------------------------------------------------------------------------- /src/substr.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module substr 4 | * @description 5 | * Alias to substr function. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the substr function 12 | * ```sh 13 | * yarn add strman.substr 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { substr } from 'strman' 18 | * // OR 19 | * import substr from 'strman.substr' 20 | * ``` 21 | * @param {String} value - The String! 22 | * @param {Number} start - Substring starts. 23 | * @param {Number} length - Substring length. 24 | * @example 25 | * substr('strman', 0, 3) 26 | * // => 'strm' 27 | * @returns {String} The Substring! 28 | */ 29 | export default (value: string, start: number, length: number): string => 30 | value.substr(start, length) 31 | -------------------------------------------------------------------------------- /src/surround.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import append from './append' 3 | /** 4 | * @module surround 5 | * @description 6 | * Surrounds a 'value' with the given 'substr'. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the surround function 13 | * ```sh 14 | * yarn add strman.surround 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { surround } from 'strman' 19 | * // OR 20 | * import surround from 'strman.surround' 21 | * ``` 22 | * @param {String} value - The String! 23 | * @param {String} substr 24 | * The substr to append on left, if substrRight is null, this is appended in right. 25 | * @param {String} substrRight - The substr to append on right. 26 | * @example 27 | * surround('strman', '<', '>') 28 | * // => '' 29 | * @returns {String} The String with surround substrs! 30 | */ 31 | export default (value: string, _substr: string = '', substrRight: ?string = null) => 32 | append(_substr, value, substrRight === null ? _substr : substrRight) 33 | -------------------------------------------------------------------------------- /src/tocamelcase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toStudlyCaps from './tostudlycaps' 3 | import toLowerCase from './tolowercase' 4 | /** 5 | * @module toCamelCase 6 | * @description 7 | * Transform to camelCase. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the toCamelCase function 14 | * ```sh 15 | * yarn add strman.tocamelcase 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { toCamelCase } from 'strman' 20 | * // OR 21 | * import toCamelCase from 'strman.tocamelcase' 22 | * ``` 23 | * @param {String} value - The String! 24 | * @example 25 | * const title = 'A Javascript string manipulation library.' 26 | * toCamelCase(title) 27 | * // => 'aJavascriptStringManipulationLibrary' 28 | * @returns {String} String in camelCase. 29 | */ 30 | export default (value: string): string => { 31 | const string = toStudlyCaps(value) 32 | return toLowerCase(string.substr(0, 1)) + string.substr(1) 33 | } 34 | -------------------------------------------------------------------------------- /src/todecamelize.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toCamelCase from './tocamelcase' 3 | import toLowerCase from './tolowercase' 4 | /** 5 | * @module toDecamelize 6 | * @description 7 | * Decamelize String 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the toDecamelize function 14 | * ```sh 15 | * yarn add strman.todecamelize 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { toDecamelize } from 'strman' 20 | * // OR 21 | * import toDecamelize from 'strman.todecamelize' 22 | * ``` 23 | * @param {String} value - The String! 24 | * @example 25 | * const title = 'A Javascript string manipulation library.' 26 | * toDecamelize(title) 27 | * // => 'a_javascript_string_manipulation_library.' 28 | * @returns {String} String decamelized. 29 | */ 30 | export default (value: string, chr: string = '_'): string => { 31 | const camel = toCamelCase(value) 32 | const string = camel.replace(/([A-Z])+/g, `${chr}$1`) 33 | return toLowerCase(string) 34 | } 35 | -------------------------------------------------------------------------------- /src/tokebabcase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toDecamelize from './todecamelize' 3 | /** 4 | * @module toKebabCase 5 | * @description 6 | * Transform to kebab-case. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the toKebabCase function 13 | * ```sh 14 | * yarn add strman.tokebabcase 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { toKebabCase } from 'strman' 19 | * // OR 20 | * import toKebabCase from 'strman.tokebabcase' 21 | * ``` 22 | * @param {String} value The String! 23 | * @example 24 | * const title = 'A Javascript string manipulation library.' 25 | * toKebabCase(title) 26 | * // => 'a-javascript-string-manipulation-library.' 27 | * @returns {String} String in kebab-case. 28 | */ 29 | export default (value: string): string => toDecamelize(value, '-') 30 | -------------------------------------------------------------------------------- /src/tolowercase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module toLowerCase 4 | * @description 5 | * Transform to lowercase. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the toLowerCase function 12 | * ```sh 13 | * yarn add strman.tolowercase 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { toLowerCase } from 'strman' 18 | * // OR 19 | * import toLowerCase from 'strman.tolowercase' 20 | * ``` 21 | * @param {String} value - The String! 22 | * @example 23 | * const title = 'A Javascript string manipulation library.' 24 | * toLowerCase(title) 25 | * // => 'a javascript string manipulation library.' 26 | * @returns {String} String in lowercase. 27 | */ 28 | export default (value: string): string => value.toLowerCase() 29 | -------------------------------------------------------------------------------- /src/tosnakecase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toDecamelize from './todecamelize' 3 | /** 4 | * @module toSnakeCase 5 | * @description 6 | * Transform to snake_case. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the toSnakeCase function 13 | * ```sh 14 | * yarn add strman.tosnakecase 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { toSnakeCase } from 'strman' 19 | * // OR 20 | * import toSnakeCase from 'strman.tosnakecase' 21 | * ``` 22 | * @param {String} value The String! 23 | * @example 24 | * const title = 'A Javascript string manipulation library.' 25 | * toSnakeCase(title) 26 | * // => 'a_javascript_string_manipulation_library.' 27 | * @returns {String} String in snake_case. 28 | */ 29 | export default (value: string): string => toDecamelize(value, '_') 30 | -------------------------------------------------------------------------------- /src/tostudlycaps.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import toUpperCase from './touppercase' 3 | /** 4 | * @module toStudlyCaps 5 | * @description 6 | * Transform to StudlyCaps. 7 | * ## Install 8 | * Install all functions of strman 9 | * ```sh 10 | * yarn add strman 11 | * ``` 12 | * or just the toStudlyCaps function 13 | * ```sh 14 | * yarn add strman.tostudlycaps 15 | * ``` 16 | * ## Usage 17 | * ```javascript 18 | * import { toStudlyCaps } from 'strman' 19 | * // OR 20 | * import toStudlyCaps from 'strman.tostudlycaps' 21 | * ``` 22 | * @param {String} value - The String! 23 | * @example 24 | * const title = 'A Javascript string manipulation library.' 25 | * toStudlyCaps(title) 26 | * // => 'AJavascriptStringManipulationLibrary.' 27 | * @returns {String} String in StudlyCaps. 28 | */ 29 | export default (value: string): string => { 30 | const string = value.replace(/[-_\s]+(.)?/g, (match, chr) => toUpperCase(chr)) 31 | return toUpperCase(string.substr(0, 1)) + string.substr(1) 32 | } 33 | -------------------------------------------------------------------------------- /src/touppercase.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | /** 3 | * @module toUpperCase 4 | * @description 5 | * Transform to uppercase. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the toUpperCase function 12 | * ```sh 13 | * yarn add strman.touppercase 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { toUpperCase } from 'strman' 18 | * // OR 19 | * import toUpperCase from 'strman.touppercase' 20 | * ``` 21 | * @param {String} value - The String! 22 | * @example 23 | * const title = 'A Javascript string manipulation library.' 24 | * toUpperCase(title) 25 | * // => 'A JAVASCRIPT STRING MANIPULATION LIBRARY.' 26 | * @returns {String} String in uppercase. 27 | */ 28 | export default (value: string): string => value.toUpperCase() 29 | -------------------------------------------------------------------------------- /src/transliterate.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import ascii from './lib/ascii' 3 | import replace from './replace' 4 | 5 | /** 6 | * @module transliterate 7 | * @description 8 | * Remove all non valid characters. Example: change á => a or ẽ => e. 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the transliterate function 15 | * ```sh 16 | * yarn add strman.transliterate 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { transliterate } from 'strman' 21 | * // OR 22 | * import transliterate from 'strman.transliterate' 23 | * ``` 24 | * @param {String} value - The String! 25 | * @example 26 | * const title = 'strmáñ' 27 | * transliterate(title) 28 | * // => 'strman' 29 | * @returns {String} String without non valid characters. 30 | */ 31 | export default (value: string): string => 32 | Object.keys(ascii).reduce( 33 | (newValue, currentKey) => 34 | ascii[currentKey].reduce( 35 | (previous, currentValue) => replace(previous, currentValue, currentKey), 36 | newValue, 37 | ), 38 | value, 39 | ) 40 | -------------------------------------------------------------------------------- /src/trim.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import leftTrim from './lefttrim' 3 | import rightTrim from './righttrim' 4 | 5 | /** 6 | * @module trim 7 | * @description 8 | * Remove all spaces on left and right. 9 | * ## Install 10 | * Install all functions of strman 11 | * ```sh 12 | * yarn add strman 13 | * ``` 14 | * or just the trim function 15 | * ```sh 16 | * yarn add strman.trim 17 | * ``` 18 | * ## Usage 19 | * ```javascript 20 | * import { trim } from 'strman' 21 | * // OR 22 | * import trim from 'strman.trim' 23 | * ``` 24 | * @param {String} value - String to remove spaces. 25 | * @param {String} [char = ' '] - if you need remove other char on boarders. 26 | * @example 27 | * const title = ' strman ' 28 | * trim(title) 29 | * // => 'strman' 30 | * @returns {String} String without boarders spaces. 31 | */ 32 | export default (value: string, char: string = ' '): string => leftTrim(rightTrim(value, char), char) 33 | -------------------------------------------------------------------------------- /src/truncate.js: -------------------------------------------------------------------------------- 1 | // @form 2 | import substr from './substr' 3 | import append from './append' 4 | /** 5 | * @module truncate 6 | * @description 7 | * Truncate the unsecured form string, cutting the independent string of required position. 8 | * ## Install 9 | * Install all functions of strman 10 | * ```sh 11 | * yarn add strman 12 | * ``` 13 | * or just the truncate function 14 | * ```sh 15 | * yarn add strman.truncate 16 | * ``` 17 | * ## Usage 18 | * ```javascript 19 | * import { truncate } from 'strman' 20 | * // OR 21 | * import truncate from 'strman.truncate' 22 | * ``` 23 | * @param {String} value - Value will be truncated unsecurely. 24 | * @param {Number} length - Size of the returned string. 25 | * @param {String} [_append = ''] - Value that will be added to the end of the return string. 26 | * @example 27 | * const title = 'A Javascript string manipulation library.' 28 | * truncate(title, 16, '...') 29 | * // => 'A Javascript ...' 30 | * @returns {String} String truncated unsafely. 31 | */ 32 | export default (value: string, length: number, _append: string = ''): string => { 33 | if (length === 0) { 34 | return '' 35 | } 36 | 37 | if (length >= value.length) { 38 | return value 39 | } 40 | 41 | const truncated = substr(value, 0, length - _append.length) 42 | 43 | return append(truncated, _append) 44 | } 45 | -------------------------------------------------------------------------------- /src/urlDecode.js: -------------------------------------------------------------------------------- 1 | // @form 2 | /** 3 | * @module urlDecode 4 | * @description 5 | * Decodes URL-encoded string 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the urlDecode function 12 | * ```sh 13 | * yarn add strman.urldecode 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { urlDecode } from 'strman' 18 | * // OR 19 | * import urlDecode from 'strman.urldecode' 20 | * ``` 21 | * @param {String} value - The string to be decoded 22 | * @example 23 | * urlDecode('https://github.com/dleitee/strman/&name=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA') 24 | * // => 'https://github.com/dleitee/strman/&name=áéíóú' 25 | * @returns {String} Returns the decoded string. 26 | */ 27 | export default (value: string): string => decodeURI(value) 28 | -------------------------------------------------------------------------------- /src/urlencode.js: -------------------------------------------------------------------------------- 1 | // @form 2 | /** 3 | * @module urlEncode 4 | * @description 5 | * Replaces all characters with the appropriate UTF-8 escape sequences. 6 | * ## Install 7 | * Install all functions of strman 8 | * ```sh 9 | * yarn add strman 10 | * ``` 11 | * or just the urlEncode function 12 | * ```sh 13 | * yarn add strman.urlencode 14 | * ``` 15 | * ## Usage 16 | * ```javascript 17 | * import { urlEncode } from 'strman' 18 | * // OR 19 | * import urlEncode from 'strman.urlencode' 20 | * ``` 21 | * @param {String} value - The string to be encoded 22 | * @example 23 | * urlEncode('https://github.com/dleitee/strman/&name=áéíóú') 24 | * // => 'https://github.com/dleitee/strman/&name=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA' 25 | * @returns {String} Returns a string in which all non-alphanumeric characters except -_. 26 | */ 27 | export default (value: string): string => encodeURI(value) 28 | -------------------------------------------------------------------------------- /strman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/strman.png -------------------------------------------------------------------------------- /strman_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/strman_new.png -------------------------------------------------------------------------------- /test/append.strman.test.js: -------------------------------------------------------------------------------- 1 | import { append } from '../src/strman' 2 | 3 | describe('strman.append', () => { 4 | test('should import append from strman', () => { 5 | expect(append('f', 'o', 'o', 'b', 'a', 'r')).toBe('foobar') 6 | expect(append('foobar')).toBe('foobar') 7 | expect(append('', 'foobar')).toBe('foobar') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/append.test.js: -------------------------------------------------------------------------------- 1 | import append from '../src/append' 2 | import { append as strmanAppend } from '../src/strman' 3 | 4 | describe('strman.append', () => { 5 | test('should be foobar', () => { 6 | expect(append('f', 'o', 'o', 'b', 'a', 'r')).toBe('foobar') 7 | expect(append('foobar')).toBe('foobar') 8 | expect(append('', 'foobar')).toBe('foobar') 9 | }) 10 | }) 11 | 12 | describe('strman.append', () => { 13 | test('should import append from strman', () => { 14 | expect(strmanAppend('f', 'o', 'o', 'b', 'a', 'r')).toBe('foobar') 15 | expect(strmanAppend('foobar')).toBe('foobar') 16 | expect(strmanAppend('', 'foobar')).toBe('foobar') 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /test/appendarray.strman.test.js: -------------------------------------------------------------------------------- 1 | import { appendArray } from '../src/strman' 2 | 3 | describe('strman.appendArray', () => { 4 | test('should import appendArray from strman', () => { 5 | expect(appendArray('f', ['o', 'o', 'b', 'a', 'r'])).toBe('foobar') 6 | expect(appendArray('foobar')).toBe('foobar') 7 | expect(appendArray('', ['foobar'])).toBe('foobar') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/appendarray.test.js: -------------------------------------------------------------------------------- 1 | import appendArray from '../src/appendarray' 2 | 3 | describe('strman.appendArray', () => { 4 | test('should be foobar', () => { 5 | expect(appendArray('f', ['o', 'o', 'b', 'a', 'r'])).toBe('foobar') 6 | expect(appendArray('foobar')).toBe('foobar') 7 | expect(appendArray('', ['foobar'])).toBe('foobar') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/at.strman.test.js: -------------------------------------------------------------------------------- 1 | import { at } from '../src/strman' 2 | 3 | describe('strman.at', () => { 4 | test('should import at from strman', () => { 5 | expect(at('foobar', 0)).toBe('f') 6 | expect(at('ofobar', 1)).toBe('f') 7 | expect(at('oobarf', -1)).toBe('f') 8 | expect(at('oobafr', -2)).toBe('f') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/at.test.js: -------------------------------------------------------------------------------- 1 | import at from '../src/at' 2 | 3 | describe('strman.at', () => { 4 | test('should be f', () => { 5 | expect(at('foobar', 0)).toBe('f') 6 | expect(at('ofobar', 1)).toBe('f') 7 | expect(at('oobarf', -1)).toBe('f') 8 | expect(at('oobafr', -2)).toBe('f') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/base64decode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { base64decode } from '../src/strman' 2 | 3 | describe('strman.base64decode', () => { 4 | test('should import base64decode from strman', () => { 5 | expect(base64decode('RGFuaWVs')).toBe('Daniel') 6 | expect(base64decode('Zm9v')).toBe('foo') 7 | expect(base64decode('YmFy')).toBe('bar') 8 | expect(base64decode('YsOhciE=')).toBe('bár!') 9 | expect(base64decode('5ryi')).toBe('漢') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/base64decode.test.js: -------------------------------------------------------------------------------- 1 | import base64decode from '../src/base64decode' 2 | 3 | describe('strman.base64decode', () => { 4 | test('should be a string decoded', () => { 5 | expect(base64decode('RGFuaWVs')).toBe('Daniel') 6 | expect(base64decode('Zm9v')).toBe('foo') 7 | expect(base64decode('YmFy')).toBe('bar') 8 | expect(base64decode('YsOhciE=')).toBe('bár!') 9 | expect(base64decode('5ryi')).toBe('漢') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/base64encode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { base64encode } from '../src/strman' 2 | 3 | describe('strman.base64encode', () => { 4 | test('should import base64decode from strman', () => { 5 | expect(base64encode('Daniel')).toBe('RGFuaWVs') 6 | expect(base64encode('foo')).toBe('Zm9v') 7 | expect(base64encode('bar')).toBe('YmFy') 8 | expect(base64encode('bár!')).toBe('YsOhciE=') 9 | expect(base64encode('漢')).toBe('5ryi') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/base64encode.test.js: -------------------------------------------------------------------------------- 1 | import base64encode from '../src/base64encode' 2 | 3 | describe('strman.base64encode', () => { 4 | test('should be a string encoded', () => { 5 | expect(base64encode('Daniel')).toBe('RGFuaWVs') 6 | expect(base64encode('foo')).toBe('Zm9v') 7 | expect(base64encode('bar')).toBe('YmFy') 8 | expect(base64encode('bár!')).toBe('YsOhciE=') 9 | expect(base64encode('漢')).toBe('5ryi') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/between.strman.test.js: -------------------------------------------------------------------------------- 1 | import between from '../src/between' 2 | 3 | describe('strman.between', () => { 4 | test('should be ["foo"]', () => { 5 | expect(between('[foo]', '[', ']')[0]).toBe('foo') 6 | expect(between('foo', '', '')[0]).toBe('foo') 7 | expect(between('barfoo', '', '')[0]).toBe('bar') 8 | expect(between('barfoo', '', '')[1]).toBe('foo') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/between.test.js: -------------------------------------------------------------------------------- 1 | import between from '../src/between' 2 | 3 | describe('strman.between', () => { 4 | test('should be ["foo"]', () => { 5 | expect(between('[foo]', '[', ']')[0]).toBe('foo') 6 | expect(between('foo', '', '')[0]).toBe('foo') 7 | expect(between('barfoo', '', '')[0]).toBe('bar') 8 | expect(between('barfoo', '', '')[1]).toBe('foo') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/bindecode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { binDecode } from '../src/strman' 2 | 3 | describe('strman.binDecode', () => { 4 | test('should be a string decoded', () => { 5 | expect(binDecode('0110111100100010')).toBe('漢') 6 | expect(binDecode('0000000001000001')).toBe('A') 7 | expect(binDecode('0000000011000001')).toBe('Á') 8 | expect(binDecode('00000000010000010000000001000001')).toBe('AA') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/bindecode.test.js: -------------------------------------------------------------------------------- 1 | import bindecode from '../src/bindecode' 2 | 3 | describe('strman.bindecode', () => { 4 | test('should be a string decoded', () => { 5 | expect(bindecode('0110111100100010')).toBe('漢') 6 | expect(bindecode('0000000001000001')).toBe('A') 7 | expect(bindecode('0000000011000001')).toBe('Á') 8 | expect(bindecode('00000000010000010000000001000001')).toBe('AA') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/binencode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { binEncode } from '../src/strman' 2 | 3 | describe('strman.binEncode', () => { 4 | test('should be a binary', () => { 5 | expect(binEncode('漢')).toBe('0110111100100010') 6 | expect(binEncode('A')).toBe('0000000001000001') 7 | expect(binEncode('Á')).toBe('0000000011000001') 8 | expect(binEncode('AA')).toBe('00000000010000010000000001000001') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/binencode.test.js: -------------------------------------------------------------------------------- 1 | import binencode from '../src/binencode' 2 | 3 | describe('strman.binencode', () => { 4 | test('should be a binary', () => { 5 | expect(binencode('漢')).toBe('0110111100100010') 6 | expect(binencode('A')).toBe('0000000001000001') 7 | expect(binencode('Á')).toBe('0000000011000001') 8 | expect(binencode('AA')).toBe('00000000010000010000000001000001') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/chars.strman.test.js: -------------------------------------------------------------------------------- 1 | import { chars } from '../src/strman' 2 | 3 | describe('strman.chars', () => { 4 | it('should be ["t", "i", "t", "l", "e"]', () => { 5 | const title = 'title' 6 | expect(chars(title)[0]).toBe('t') 7 | expect(chars(title)[1]).toBe('i') 8 | expect(chars(title)[2]).toBe('t') 9 | expect(chars(title)[3]).toBe('l') 10 | expect(chars(title)[4]).toBe('e') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/chars.test.js: -------------------------------------------------------------------------------- 1 | import chars from '../src/chars' 2 | 3 | describe('strman.chars', () => { 4 | it('should be ["t", "i", "t", "l", "e"]', () => { 5 | const title = 'title' 6 | expect(chars(title)[0]).toBe('t') 7 | expect(chars(title)[1]).toBe('i') 8 | expect(chars(title)[2]).toBe('t') 9 | expect(chars(title)[3]).toBe('l') 10 | expect(chars(title)[4]).toBe('e') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/collapsewhitespace.strman.test.js: -------------------------------------------------------------------------------- 1 | import { collapseWhitespace } from '../src/strman' 2 | 3 | describe('strman.collapseWhitespace', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['foo bar', ' foo bar ', ' foo bar ', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(collapseWhitespace(el)).toBe('foo bar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/collapsewhitespace.test.js: -------------------------------------------------------------------------------- 1 | import collapseWhitespace from '../src/collapsewhitespace' 2 | 3 | describe('strman.collapseWhitespace', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['foo bar', ' foo bar ', ' foo bar ', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(collapseWhitespace(el)).toBe('foo bar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/compare.strman.test.js: -------------------------------------------------------------------------------- 1 | import { compare } from '../src/strman' 2 | 3 | describe('strman.compare', () => { 4 | test('should be 1, -1, 0', () => { 5 | expect(compare('a', 'b')).toBe(-1) 6 | expect(compare('b', 'a')).toBe(1) 7 | expect(compare('a', 'a')).toBe(0) 8 | expect(compare('0', '1')).toBe(-1) 9 | expect(compare('1', '0')).toBe(1) 10 | expect(compare('0', '0')).toBe(0) 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/compare.test.js: -------------------------------------------------------------------------------- 1 | import compare from '../src/compare' 2 | 3 | describe('strman.compare', () => { 4 | test('should be 1, -1, 0', () => { 5 | expect(compare('a', 'b')).toBe(-1) 6 | expect(compare('b', 'a')).toBe(1) 7 | expect(compare('a', 'a')).toBe(0) 8 | expect(compare('0', '1')).toBe(-1) 9 | expect(compare('1', '0')).toBe(1) 10 | expect(compare('0', '0')).toBe(0) 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/contains.strman.test.js: -------------------------------------------------------------------------------- 1 | import { contains } from '../src/strman' 2 | 3 | describe('strman.contains', () => { 4 | test('should be true, caseSensitive = true', () => { 5 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(contains(el, 'foo', true)).toBe(true) 9 | }) 10 | }) 11 | 12 | test('should be true, caseSensitive = false', () => { 13 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(contains(el, 'FOO', false)).toBe(true) 17 | }) 18 | }) 19 | 20 | test('should be false, caseSensitive = true', () => { 21 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(contains(el, 'FOO', true)).toBe(false) 25 | }) 26 | }) 27 | 28 | test('should be false, caseSensitive = false', () => { 29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 30 | 31 | fixtures.forEach((el) => { 32 | expect(contains(el, 'dleitee', false)).toBe(false) 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /test/contains.test.js: -------------------------------------------------------------------------------- 1 | import contains from '../src/contains' 2 | 3 | describe('strman.contains', () => { 4 | test('should be true, caseSensitive = true', () => { 5 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(contains(el, 'foo', true)).toBe(true) 9 | }) 10 | }) 11 | 12 | test('should be true, caseSensitive = false', () => { 13 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(contains(el, 'FOO', false)).toBe(true) 17 | }) 18 | }) 19 | 20 | test('should be false, caseSensitive = true', () => { 21 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(contains(el, 'FOO', true)).toBe(false) 25 | }) 26 | }) 27 | 28 | test('should be false, caseSensitive = false', () => { 29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 30 | 31 | fixtures.forEach((el) => { 32 | expect(contains(el, 'dleitee', false)).toBe(false) 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /test/containsall.strman.test.js: -------------------------------------------------------------------------------- 1 | import { containsAll } from '../src/strman' 2 | 3 | describe('strman.containsAll', () => { 4 | test('should be true, if needle = []', () => { 5 | expect(containsAll('a', [], true)).toBe(false) 6 | }) 7 | 8 | test('should be true, caseSensitive = true', () => { 9 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 10 | 11 | fixtures.forEach((el) => { 12 | expect(containsAll(el, ['foo', 'bar'], true)).toBe(true) 13 | }) 14 | }) 15 | 16 | test('should be true, caseSensitive = false', () => { 17 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 18 | 19 | fixtures.forEach((el) => { 20 | expect(containsAll(el, ['FOO', 'BAR'], false)).toBe(true) 21 | }) 22 | }) 23 | 24 | test('should be false, caseSensitive = true', () => { 25 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo'] 26 | 27 | fixtures.forEach((el) => { 28 | expect(containsAll(el, ['FOO', 'BAR'], true)).toBe(false) 29 | }) 30 | }) 31 | 32 | test('should be false, caseSensitive = false', () => { 33 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 34 | 35 | fixtures.forEach((el) => { 36 | expect(containsAll(el, ['foo', 'bar', 'dleitee'], false)).toBe(false) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /test/containsall.test.js: -------------------------------------------------------------------------------- 1 | import containsAll from '../src/containsall' 2 | 3 | describe('strman.containsAll', () => { 4 | test('should be true, if needle = []', () => { 5 | expect(containsAll('a', [], true)).toBe(false) 6 | }) 7 | 8 | test('should be true, caseSensitive = true', () => { 9 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 10 | 11 | fixtures.forEach((el) => { 12 | expect(containsAll(el, ['foo', 'bar'], true)).toBe(true) 13 | }) 14 | }) 15 | 16 | test('should be true, caseSensitive = false', () => { 17 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 18 | 19 | fixtures.forEach((el) => { 20 | expect(containsAll(el, ['FOO', 'BAR'], false)).toBe(true) 21 | }) 22 | }) 23 | 24 | test('should be false, caseSensitive = true', () => { 25 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo'] 26 | 27 | fixtures.forEach((el) => { 28 | expect(containsAll(el, ['FOO', 'BAR'], true)).toBe(false) 29 | }) 30 | }) 31 | 32 | test('should be false, caseSensitive = false', () => { 33 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 34 | 35 | fixtures.forEach((el) => { 36 | expect(containsAll(el, ['foo', 'bar', 'dleitee'], false)).toBe(false) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /test/containsany.strman.test.js: -------------------------------------------------------------------------------- 1 | import { containsAny } from '../src/strman' 2 | 3 | describe('strman.containsAny', () => { 4 | test('should be true, caseSensitive = true', () => { 5 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(containsAny(el, ['foo', 'bar', 'test'], true)).toBe(true) 9 | }) 10 | }) 11 | 12 | test('should be true, caseSensitive = false', () => { 13 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(containsAny(el, ['FOO', 'BAR', 'Test'], false)).toBe(true) 17 | }) 18 | }) 19 | 20 | test('should be false, caseSensitive = true', () => { 21 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(containsAny(el, ['FOO', 'BAR', 'TEST'], true)).toBe(false) 25 | }) 26 | }) 27 | 28 | test('should be false, caseSensitive = false', () => { 29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 30 | 31 | fixtures.forEach((el) => { 32 | expect(containsAny(el, ['dleitee'], false)).toBe(false) 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /test/containsany.test.js: -------------------------------------------------------------------------------- 1 | import containsAny from '../src/containsany' 2 | 3 | describe('strman.containsAny', () => { 4 | test('should be true, caseSensitive = true', () => { 5 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(containsAny(el, ['foo', 'bar', 'test'], true)).toBe(true) 9 | }) 10 | }) 11 | 12 | test('should be true, caseSensitive = false', () => { 13 | const fixtures = ['foo bar', 'bar foo', 'foobar'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(containsAny(el, ['FOO', 'BAR', 'Test'], false)).toBe(true) 17 | }) 18 | }) 19 | 20 | test('should be false, caseSensitive = true', () => { 21 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(containsAny(el, ['FOO', 'BAR', 'TEST'], true)).toBe(false) 25 | }) 26 | }) 27 | 28 | test('should be false, caseSensitive = false', () => { 29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo'] 30 | 31 | fixtures.forEach((el) => { 32 | expect(containsAny(el, ['dleitee'], false)).toBe(false) 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /test/countsubstr.strman.test.js: -------------------------------------------------------------------------------- 1 | import { countSubstr } from '../src/strman' 2 | 3 | describe('strman.countSubstr', () => { 4 | test('should be 7', () => { 5 | const fixtures = ['aaaaaAaaAA', 'faaaAAaaaaAA', 'aaAAaaaaafA', 'AAaaafaaaaAAAA'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(countSubstr(el, 'a')).toBe(7) 9 | }) 10 | }) 11 | 12 | test('should be 7 without caseSensitive', () => { 13 | const fixtures = ['aaaaaaa', 'faaaaaaa', 'aaaaaaaf', 'aaafaaaa'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(countSubstr(el, 'A', false)).toBe(7) 17 | }) 18 | }) 19 | 20 | test('should be 2 with allowOverlaping', () => { 21 | expect(countSubstr('aaa', 'aa', true, true)).toBe(2) 22 | }) 23 | 24 | test('should be 1 without allowOverlaping', () => { 25 | expect(countSubstr('aaa', 'aa', true, false)).toBe(1) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/countsubstr.test.js: -------------------------------------------------------------------------------- 1 | import countSubstr from '../src/countsubstr' 2 | 3 | describe('strman.countSubstr', () => { 4 | test('should be 7', () => { 5 | const fixtures = ['aaaaaAaaAA', 'faaaAAaaaaAA', 'aaAAaaaaafA', 'AAaaafaaaaAAAA'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(countSubstr(el, 'a')).toBe(7) 9 | }) 10 | }) 11 | 12 | test('should be 7 without caseSensitive', () => { 13 | const fixtures = ['aaaaaaa', 'faaaaaaa', 'aaaaaaaf', 'aaafaaaa'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(countSubstr(el, 'A', false)).toBe(7) 17 | }) 18 | }) 19 | 20 | test('should be 2 with allowOverlaping', () => { 21 | expect(countSubstr('aaa', 'aa', true, true)).toBe(2) 22 | }) 23 | 24 | test('should be 1 without allowOverlaping', () => { 25 | expect(countSubstr('aaa', 'aa', true, false)).toBe(1) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/decdecode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { decDecode } from '../src/strman' 2 | 3 | describe('strman.decDecode', () => { 4 | test('should be string', () => { 5 | expect(decDecode('28450')).toBe('漢') 6 | expect(decDecode('00065')).toBe('A') 7 | expect(decDecode('00193')).toBe('Á') 8 | expect(decDecode('0006500065')).toBe('AA') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/decdecode.test.js: -------------------------------------------------------------------------------- 1 | import decDecode from '../src/decdecode' 2 | 3 | describe('strman.decDecode', () => { 4 | test('should be string', () => { 5 | expect(decDecode('28450')).toBe('漢') 6 | expect(decDecode('00065')).toBe('A') 7 | expect(decDecode('00193')).toBe('Á') 8 | expect(decDecode('0006500065')).toBe('AA') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/decencode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { decEncode } from '../src/strman' 2 | 3 | describe('strman.decEncode', () => { 4 | test('should be binary', () => { 5 | expect(decEncode('漢')).toBe('28450') 6 | expect(decEncode('A')).toBe('00065') 7 | expect(decEncode('Á')).toBe('00193') 8 | expect(decEncode('AA')).toBe('0006500065') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/decencode.test.js: -------------------------------------------------------------------------------- 1 | import decEncode from '../src/decencode' 2 | 3 | describe('strman.decEncode', () => { 4 | test('should be binary', () => { 5 | expect(decEncode('漢')).toBe('28450') 6 | expect(decEncode('A')).toBe('00065') 7 | expect(decEncode('Á')).toBe('00193') 8 | expect(decEncode('AA')).toBe('0006500065') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/endswith.strman.test.js: -------------------------------------------------------------------------------- 1 | import { endsWith } from '../src/strman' 2 | 3 | describe('strman.endsWith', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foo bar', 'bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(endsWith(el, 'bar')).toBe(true) 9 | }) 10 | 11 | const fixtures2 = ['foo barr', 'barr'] 12 | 13 | fixtures2.forEach((el) => { 14 | expect(endsWith(el, 'bar', el.length - 1)).toBe(true) 15 | }) 16 | }) 17 | }) 18 | 19 | describe('strman.endsWith caseSensitive', () => { 20 | test('should be true', () => { 21 | const fixtures = ['foo bar', 'bar'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(endsWith(el, 'BAR', null, false)).toBe(true) 25 | }) 26 | 27 | const fixtures2 = ['foo barr', 'barr'] 28 | 29 | fixtures2.forEach((el) => { 30 | expect(endsWith(el, 'BAR', el.length - 1, false)).toBe(true) 31 | }) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /test/endswith.test.js: -------------------------------------------------------------------------------- 1 | import endsWith from '../src/endswith' 2 | 3 | describe('strman.endsWith', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foo bar', 'bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(endsWith(el, 'bar')).toBe(true) 9 | }) 10 | 11 | const fixtures2 = ['foo barr', 'barr'] 12 | 13 | fixtures2.forEach((el) => { 14 | expect(endsWith(el, 'bar', el.length - 1)).toBe(true) 15 | }) 16 | }) 17 | }) 18 | 19 | describe('strman.endsWith caseSensitive', () => { 20 | test('should be true', () => { 21 | const fixtures = ['foo bar', 'bar'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(endsWith(el, 'BAR', null, false)).toBe(true) 25 | }) 26 | 27 | const fixtures2 = ['foo barr', 'barr'] 28 | 29 | fixtures2.forEach((el) => { 30 | expect(endsWith(el, 'BAR', el.length - 1, false)).toBe(true) 31 | }) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /test/ensureleft.strman.test.js: -------------------------------------------------------------------------------- 1 | import { ensureLeft } from '../src/strman' 2 | 3 | describe('strman.ensureLeft', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['bar', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(ensureLeft(el, 'foo')).toBe('foobar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/ensureleft.test.js: -------------------------------------------------------------------------------- 1 | import ensureLeft from '../src/ensureleft' 2 | 3 | describe('strman.ensureLeft', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['bar', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(ensureLeft(el, 'foo')).toBe('foobar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/ensureright.strman.test.js: -------------------------------------------------------------------------------- 1 | import { ensureRight } from '../src/strman' 2 | 3 | describe('strman.ensureRight', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['foo', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(ensureRight(el, 'bar')).toBe('foobar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/ensureright.test.js: -------------------------------------------------------------------------------- 1 | import ensureRight from '../src/ensureright' 2 | 3 | describe('strman.ensureRight', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['foo', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(ensureRight(el, 'bar')).toBe('foobar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/equal.strman.test.js: -------------------------------------------------------------------------------- 1 | import { equal } from '../src/strman' 2 | 3 | describe('strman.equal', () => { 4 | test('should be true or false', () => { 5 | expect(equal('a', 'b')).toBe(false) 6 | expect(equal('a', 'a')).toBe(true) 7 | expect(equal('0', 0)).toBe(false) 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/equal.test.js: -------------------------------------------------------------------------------- 1 | import equal from '../src/equal' 2 | 3 | describe('strman.equal', () => { 4 | test('should be true or false', () => { 5 | expect(equal('a', 'b')).toBe(false) 6 | expect(equal('a', 'a')).toBe(true) 7 | expect(equal('0', 0)).toBe(false) 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/first.strman.test.js: -------------------------------------------------------------------------------- 1 | import { first } from '../src/strman' 2 | 3 | describe('strman.first', () => { 4 | test('should be foo', () => { 5 | const fixtures = ['foo', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(first(el, 3)).toBe('foo') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/first.test.js: -------------------------------------------------------------------------------- 1 | import first from '../src/first' 2 | 3 | describe('strman.first', () => { 4 | test('should be foo', () => { 5 | const fixtures = ['foo', 'foobar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(first(el, 3)).toBe('foo') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/format.strman.test.js: -------------------------------------------------------------------------------- 1 | import { format } from '../src/strman' 2 | 3 | describe('strman.format', () => { 4 | test('should be formated strings', () => { 5 | expect(format('foo bar')).toBe('foo bar') 6 | expect(format('{0} bar', ['foo'])).toBe('foo bar') 7 | expect(format('foo {0}', ['bar'])).toBe('foo bar') 8 | expect(format('foo {0}', ['bar', 'foo'])).toBe('foo bar') 9 | expect(format('{0} {1}', ['foo', 'bar'])).toBe('foo bar') 10 | expect(format('{1} {0}', ['bar', 'foo'])).toBe('foo bar') 11 | expect(format('{1} {0}', ['bar'])).toBe('{1} bar') 12 | expect(format('{foo} bar', { foo: 'foo' })).toBe('foo bar') 13 | expect(format('{foo} {bar}', { 14 | foo: 'foo', 15 | bar: 'bar', 16 | })).toBe('foo bar') 17 | }) 18 | 19 | test('should be {0}', () => { 20 | expect(format('foo bar {0}')).toBe('foo bar {0}') 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /test/format.test.js: -------------------------------------------------------------------------------- 1 | import format from '../src/format' 2 | 3 | describe('strman.format', () => { 4 | test('should be formated strings', () => { 5 | expect(format('foo bar')).toBe('foo bar') 6 | expect(format('{0} bar', ['foo'])).toBe('foo bar') 7 | expect(format('foo {0}', ['bar'])).toBe('foo bar') 8 | expect(format('foo {0}', ['bar', 'foo'])).toBe('foo bar') 9 | expect(format('{0} {1}', ['foo', 'bar'])).toBe('foo bar') 10 | expect(format('{1} {0}', ['bar', 'foo'])).toBe('foo bar') 11 | expect(format('{1} {0}', ['bar'])).toBe('{1} bar') 12 | expect(format('{foo} bar', { foo: 'foo' })).toBe('foo bar') 13 | expect(format('{foo} {bar}', { 14 | foo: 'foo', 15 | bar: 'bar', 16 | })).toBe('foo bar') 17 | }) 18 | 19 | test('should be {0}', () => { 20 | expect(format('foo bar {0}')).toBe('foo bar {0}') 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /test/hexdecode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { hexDecode } from '../src/strman' 2 | 3 | describe('strman.hexDecode', () => { 4 | test('should be string', () => { 5 | expect(hexDecode('6f22')).toBe('漢') 6 | expect(hexDecode('0041')).toBe('A') 7 | expect(hexDecode('00c1')).toBe('Á') 8 | expect(hexDecode('00410041')).toBe('AA') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/hexdecode.test.js: -------------------------------------------------------------------------------- 1 | import hexDecode from '../src/hexdecode' 2 | 3 | describe('strman.hexDecode', () => { 4 | test('should be string', () => { 5 | expect(hexDecode('6f22')).toBe('漢') 6 | expect(hexDecode('0041')).toBe('A') 7 | expect(hexDecode('00c1')).toBe('Á') 8 | expect(hexDecode('00410041')).toBe('AA') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/hexencode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { hexEncode } from '../src/strman' 2 | 3 | describe('strman.hexEncode', () => { 4 | test('should be hexadecimal', () => { 5 | expect(hexEncode('漢')).toBe('6f22') 6 | expect(hexEncode('A')).toBe('0041') 7 | expect(hexEncode('Á')).toBe('00c1') 8 | expect(hexEncode('AA')).toBe('00410041') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/hexencode.test.js: -------------------------------------------------------------------------------- 1 | import hexEncode from '../src/hexencode' 2 | 3 | describe('strman.hexEncode', () => { 4 | test('should be hexadecimal', () => { 5 | expect(hexEncode('漢')).toBe('6f22') 6 | expect(hexEncode('A')).toBe('0041') 7 | expect(hexEncode('Á')).toBe('00c1') 8 | expect(hexEncode('AA')).toBe('00410041') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/htmldecode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { htmlDecode } from '../src/strman' 2 | 3 | describe('strman.htmlDecode', () => { 4 | test('should be decoded html', () => { 5 | expect(htmlDecode('á')).toBe('\u00E1') 6 | expect(htmlDecode('Ш')).toBe('Ш') 7 | expect(htmlDecode('Ж')).toBe('Ж') 8 | expect(htmlDecode('┐')).toBe('┐') 9 | expect(htmlDecode('&boxdlaaa;')).toBe('&boxdlaaa;') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/htmldecode.test.js: -------------------------------------------------------------------------------- 1 | import htmlDecode from '../src/htmldecode' 2 | 3 | describe('strman.htmlDecode', () => { 4 | test('should be decoded html', () => { 5 | expect(htmlDecode('á')).toBe('\u00E1') 6 | expect(htmlDecode('Ш')).toBe('Ш') 7 | expect(htmlDecode('Ж')).toBe('Ж') 8 | expect(htmlDecode('┐')).toBe('┐') 9 | expect(htmlDecode('&boxdlaaa;')).toBe('&boxdlaaa;') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/htmlencode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { htmlEncode } from '../src/strman' 2 | 3 | describe('strman.htmlEncode', () => { 4 | test('should be encoded html', () => { 5 | expect(htmlEncode('á')).toBe('á') 6 | expect(htmlEncode('áéíóú')).toBe('áéíóú') 7 | expect(htmlEncode('Ш')).toBe('Ш') 8 | expect(htmlEncode('Ж')).toBe('Ж') 9 | expect(htmlEncode('┐')).toBe('┐') 10 | expect(htmlEncode('a')).toBe('a') 11 | expect(htmlEncode('¶')).toBe('¶') 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /test/htmlencode.test.js: -------------------------------------------------------------------------------- 1 | import htmlEncode from '../src/htmlencode' 2 | 3 | describe('strman.htmlEncode', () => { 4 | test('should be encoded html', () => { 5 | expect(htmlEncode('á')).toBe('á') 6 | expect(htmlEncode('áéíóú')).toBe('áéíóú') 7 | expect(htmlEncode('Ш')).toBe('Ш') 8 | expect(htmlEncode('Ж')).toBe('Ж') 9 | expect(htmlEncode('┐')).toBe('┐') 10 | expect(htmlEncode('a')).toBe('a') 11 | expect(htmlEncode('¶')).toBe('¶') 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /test/indexof.strman.test.js: -------------------------------------------------------------------------------- 1 | import { indexOf } from '../src/strman' 2 | 3 | describe('strman.indexOf', () => { 4 | test('should be true', () => { 5 | const value = 'foobar' 6 | expect(indexOf(value, 'f')).toBe(0) 7 | expect(indexOf(value, 'o')).toBe(1) 8 | expect(indexOf(value, 'b')).toBe(3) 9 | expect(indexOf(value, 'a')).toBe(4) 10 | expect(indexOf(value, 'r')).toBe(5) 11 | expect(indexOf(value, 't')).toBe(-1) 12 | }) 13 | }) 14 | 15 | describe('strman.indexOf caseSensitive', () => { 16 | test('should be true', () => { 17 | const value = 'FOOBAR' 18 | expect(indexOf(value, 'f', undefined, false)).toBe(0) 19 | expect(indexOf(value, 'o', undefined, false)).toBe(1) 20 | expect(indexOf(value, 'b', undefined, false)).toBe(3) 21 | expect(indexOf(value, 'a', undefined, false)).toBe(4) 22 | expect(indexOf(value, 'r', undefined, false)).toBe(5) 23 | expect(indexOf(value, 't', undefined, false)).toBe(-1) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /test/indexof.test.js: -------------------------------------------------------------------------------- 1 | import indexOf from '../src/indexof' 2 | 3 | describe('strman.indexOf', () => { 4 | test('should be true', () => { 5 | const value = 'foobar' 6 | expect(indexOf(value, 'f')).toBe(0) 7 | expect(indexOf(value, 'o')).toBe(1) 8 | expect(indexOf(value, 'b')).toBe(3) 9 | expect(indexOf(value, 'a')).toBe(4) 10 | expect(indexOf(value, 'r')).toBe(5) 11 | expect(indexOf(value, 't')).toBe(-1) 12 | }) 13 | }) 14 | 15 | describe('strman.indexOf caseSensitive', () => { 16 | test('should be true', () => { 17 | const value = 'FOOBAR' 18 | expect(indexOf(value, 'f', undefined, false)).toBe(0) 19 | expect(indexOf(value, 'o', undefined, false)).toBe(1) 20 | expect(indexOf(value, 'b', undefined, false)).toBe(3) 21 | expect(indexOf(value, 'a', undefined, false)).toBe(4) 22 | expect(indexOf(value, 'r', undefined, false)).toBe(5) 23 | expect(indexOf(value, 't', undefined, false)).toBe(-1) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /test/inequal.strman.test.js: -------------------------------------------------------------------------------- 1 | import { inequal } from '../src/strman' 2 | 3 | describe('strman.inequal', () => { 4 | test('should be true or false', () => { 5 | expect(inequal('a', 'b')).toBe(true) 6 | expect(inequal('a', 'a')).toBe(false) 7 | expect(inequal('0', 0)).toBe(true) 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/inequal.test.js: -------------------------------------------------------------------------------- 1 | import inequal from '../src/inequal' 2 | 3 | describe('strman.inequal', () => { 4 | test('should be true or false', () => { 5 | expect(inequal('a', 'b')).toBe(true) 6 | expect(inequal('a', 'a')).toBe(false) 7 | expect(inequal('0', 0)).toBe(true) 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/insert.strman.test.js: -------------------------------------------------------------------------------- 1 | import { insert } from '../src/strman' 2 | 3 | describe('strman.insert', () => { 4 | test('should be foo bar', () => { 5 | expect(insert('fbar', 'oo ', 1)).toBe('foo bar') 6 | expect(insert('foo', ' bar', 3)).toBe('foo bar') 7 | expect(insert('foo bar', 'asadasd', 13)).toBe('foo bar') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/insert.test.js: -------------------------------------------------------------------------------- 1 | import insert from '../src/insert' 2 | 3 | describe('strman.insert', () => { 4 | test('should be foo bar', () => { 5 | expect(insert('fbar', 'oo ', 1)).toBe('foo bar') 6 | expect(insert('foo', ' bar', 3)).toBe('foo bar') 7 | expect(insert('foo bar', 'asadasd', 13)).toBe('foo bar') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/islowercase.strman.test.js: -------------------------------------------------------------------------------- 1 | import { isLowerCase } from '../src/strman' 2 | 3 | describe('strman.isLowerCase', () => { 4 | test('should be true', () => { 5 | const fixtures = ['', 'foo', 'foobarfoo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(isLowerCase(el)).toBe(true) 9 | }) 10 | }) 11 | test('should be false', () => { 12 | const fixtures = ['fooA', 'foobarfoAo'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(isLowerCase(el)).toBe(false) 16 | }) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /test/islowercase.test.js: -------------------------------------------------------------------------------- 1 | import isLowerCase from '../src/islowercase' 2 | 3 | describe('strman.isLowerCase', () => { 4 | test('should be true', () => { 5 | const fixtures = ['', 'foo', 'foobarfoo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(isLowerCase(el)).toBe(true) 9 | }) 10 | }) 11 | test('should be false', () => { 12 | const fixtures = ['fooA', 'foobarfoAo'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(isLowerCase(el)).toBe(false) 16 | }) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /test/isstring.strman.test.js: -------------------------------------------------------------------------------- 1 | import { isString } from '../src/strman' 2 | 3 | describe('strman.isString', () => { 4 | test('should be false', () => { 5 | const fixtures = [1, false, 1.2, [], {}] 6 | fixtures.forEach((el) => { 7 | expect(isString(el)).toBe(false) 8 | }) 9 | }) 10 | 11 | test('should be true', () => { 12 | const fixtures = ['string', '', 'áéíóú'] 13 | fixtures.forEach((el) => { 14 | expect(isString(el)).toBe(true) 15 | }) 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /test/isstring.test.js: -------------------------------------------------------------------------------- 1 | import isString from '../src/isstring' 2 | 3 | describe('strman.isString', () => { 4 | test('should be false', () => { 5 | const fixtures = [1, false, 1.2, [], {}] 6 | fixtures.forEach((el) => { 7 | expect(isString(el)).toBe(false) 8 | }) 9 | }) 10 | 11 | test('should be true', () => { 12 | const fixtures = ['string', '', 'áéíóú'] 13 | fixtures.forEach((el) => { 14 | expect(isString(el)).toBe(true) 15 | }) 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /test/isuppercase.strman.test.js: -------------------------------------------------------------------------------- 1 | import { isUpperCase } from '../src/strman' 2 | 3 | describe('strman.isUpperCase', () => { 4 | test('should be true', () => { 5 | const fixtures = ['', 'FOO', 'FOOBARFOO'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(isUpperCase(el)).toBe(true) 9 | }) 10 | }) 11 | test('should be false', () => { 12 | const fixtures = ['FOOa', 'FOOBARFOOa'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(isUpperCase(el)).toBe(false) 16 | }) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /test/isuppercase.test.js: -------------------------------------------------------------------------------- 1 | import isUpperCase from '../src/isuppercase' 2 | 3 | describe('strman.isUpperCase', () => { 4 | test('should be true', () => { 5 | const fixtures = ['', 'FOO', 'FOOBARFOO'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(isUpperCase(el)).toBe(true) 9 | }) 10 | }) 11 | test('should be false', () => { 12 | const fixtures = ['FOOa', 'FOOBARFOOa'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(isUpperCase(el)).toBe(false) 16 | }) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /test/last.strman.test.js: -------------------------------------------------------------------------------- 1 | import { last } from '../src/strman' 2 | 3 | describe('strman.last', () => { 4 | test('should be foo', () => { 5 | const fixtures = ['foo', 'foobarfoo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(last(el, 3)).toBe('foo') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/last.test.js: -------------------------------------------------------------------------------- 1 | import last from '../src/last' 2 | 3 | describe('strman.last', () => { 4 | test('should be foo', () => { 5 | const fixtures = ['foo', 'foobarfoo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(last(el, 3)).toBe('foo') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/lastindexof.strman.test.js: -------------------------------------------------------------------------------- 1 | import { lastIndexOf } from '../src/strman' 2 | 3 | describe('strman.lastIndexOf', () => { 4 | test('should be true', () => { 5 | const value = 'foobarfoobar' 6 | expect(lastIndexOf(value, 'f')).toBe(6) 7 | expect(lastIndexOf(value, 'o')).toBe(8) 8 | expect(lastIndexOf(value, 'b')).toBe(9) 9 | expect(lastIndexOf(value, 'a')).toBe(10) 10 | expect(lastIndexOf(value, 'r')).toBe(11) 11 | expect(lastIndexOf(value, 't')).toBe(-1) 12 | }) 13 | }) 14 | 15 | describe('strman.lastIndexOf caseSensitive', () => { 16 | test('should be true', () => { 17 | const value = 'foobarfoobar' 18 | expect(lastIndexOf(value, 'F', undefined, false)).toBe(6) 19 | expect(lastIndexOf(value, 'O', undefined, false)).toBe(8) 20 | expect(lastIndexOf(value, 'B', undefined, false)).toBe(9) 21 | expect(lastIndexOf(value, 'A', undefined, false)).toBe(10) 22 | expect(lastIndexOf(value, 'R', undefined, false)).toBe(11) 23 | expect(lastIndexOf(value, 'T', undefined, false)).toBe(-1) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /test/lastindexof.test.js: -------------------------------------------------------------------------------- 1 | import lastIndexOf from '../src/lastindexof' 2 | 3 | describe('strman.lastIndexOf', () => { 4 | test('should be true', () => { 5 | const value = 'foobarfoobar' 6 | expect(lastIndexOf(value, 'f')).toBe(6) 7 | expect(lastIndexOf(value, 'o')).toBe(8) 8 | expect(lastIndexOf(value, 'b')).toBe(9) 9 | expect(lastIndexOf(value, 'a')).toBe(10) 10 | expect(lastIndexOf(value, 'r')).toBe(11) 11 | expect(lastIndexOf(value, 't')).toBe(-1) 12 | }) 13 | }) 14 | 15 | describe('strman.lastIndexOf caseSensitive', () => { 16 | test('should be true', () => { 17 | const value = 'foobarfoobar' 18 | expect(lastIndexOf(value, 'F', undefined, false)).toBe(6) 19 | expect(lastIndexOf(value, 'O', undefined, false)).toBe(8) 20 | expect(lastIndexOf(value, 'B', undefined, false)).toBe(9) 21 | expect(lastIndexOf(value, 'A', undefined, false)).toBe(10) 22 | expect(lastIndexOf(value, 'R', undefined, false)).toBe(11) 23 | expect(lastIndexOf(value, 'T', undefined, false)).toBe(-1) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /test/leftpad.strman.test.js: -------------------------------------------------------------------------------- 1 | import { leftPad } from '../src/strman' 2 | 3 | describe('strman.leftPad', () => { 4 | test('should be a string 00001', () => { 5 | expect(leftPad('1', 5, '00')).toBe('00001') 6 | expect(leftPad('1', 5, 0)).toBe('00001') 7 | expect(leftPad('01', 5, 0)).toBe('00001') 8 | expect(leftPad('001', 5, 0)).toBe('00001') 9 | expect(leftPad('0001', 5, 0)).toBe('00001') 10 | expect(leftPad('00001', 5, 0)).toBe('00001') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/leftpad.test.js: -------------------------------------------------------------------------------- 1 | import leftpad from '../src/leftpad' 2 | 3 | describe('strman.leftpad', () => { 4 | test('should be a string 00001', () => { 5 | expect(leftpad('1', 5, '00')).toBe('00001') 6 | expect(leftpad('1', 5, 0)).toBe('00001') 7 | expect(leftpad('01', 5, 0)).toBe('00001') 8 | expect(leftpad('001', 5, 0)).toBe('00001') 9 | expect(leftpad('0001', 5, 0)).toBe('00001') 10 | expect(leftpad('00001', 5, 0)).toBe('00001') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/lefttrim.strman.test.js: -------------------------------------------------------------------------------- 1 | import { leftTrim } from '../src/strman' 2 | 3 | describe('strman.leftTrim', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['foo bar ', ' foo bar ', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(leftTrim(el)).toBe('foo bar ') 9 | }) 10 | }) 11 | 12 | test('should be foo bar without @', () => { 13 | const fixtures = ['foo bar@', '@foo bar@', '@@@foo bar@'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(leftTrim(el, '@')).toBe('foo bar@') 17 | }) 18 | }) 19 | 20 | test('should be foo bar without @ and with #', () => { 21 | const fixtures = ['@#foo bar@', '@#foo bar@', '@@#foo bar@'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(leftTrim(el, '@')).toBe('#foo bar@') 25 | }) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/lefttrim.test.js: -------------------------------------------------------------------------------- 1 | import lefttrim from '../src/lefttrim' 2 | 3 | describe('strman.lefttrim', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['foo bar ', ' foo bar ', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(lefttrim(el)).toBe('foo bar ') 9 | }) 10 | }) 11 | 12 | test('should be foo bar without @', () => { 13 | const fixtures = ['foo bar@', '@foo bar@', '@@@foo bar@'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(lefttrim(el, '@')).toBe('foo bar@') 17 | }) 18 | }) 19 | 20 | test('should be foo bar without @ and with #', () => { 21 | const fixtures = ['@#foo bar@', '@#foo bar@', '@@#foo bar@'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(lefttrim(el, '@')).toBe('#foo bar@') 25 | }) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/prepend.strman.test.js: -------------------------------------------------------------------------------- 1 | import { prepend } from '../src/strman' 2 | 3 | describe('strman.prepend', () => { 4 | test('should be foobar', () => { 5 | expect(prepend('r', 'f', 'o', 'o', 'b', 'a')).toBe('foobar') 6 | expect(prepend('foobar')).toBe('foobar') 7 | expect(prepend('', 'foobar')).toBe('foobar') 8 | expect(prepend('bar', 'foo')).toBe('foobar') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/prepend.test.js: -------------------------------------------------------------------------------- 1 | import prepend from '../src/prepend' 2 | 3 | describe('strman.prepend', () => { 4 | test('should be foobar', () => { 5 | expect(prepend('r', 'f', 'o', 'o', 'b', 'a')).toBe('foobar') 6 | expect(prepend('foobar')).toBe('foobar') 7 | expect(prepend('', 'foobar')).toBe('foobar') 8 | expect(prepend('bar', 'foo')).toBe('foobar') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/prependarray.strman.test.js: -------------------------------------------------------------------------------- 1 | import { prependArray } from '../src/strman' 2 | 3 | describe('strman.prependArray', () => { 4 | test('should be foobar', () => { 5 | expect(prependArray('r', ['f', 'o', 'o', 'b', 'a'])).toBe('foobar') 6 | expect(prependArray('foobar')).toBe('foobar') 7 | expect(prependArray('', ['foobar'])).toBe('foobar') 8 | expect(prependArray('bar', ['foo'])).toBe('foobar') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/prependarray.test.js: -------------------------------------------------------------------------------- 1 | import prependArray from '../src/prependarray' 2 | 3 | describe('strman.prependArray', () => { 4 | test('should be foobar', () => { 5 | expect(prependArray('r', ['f', 'o', 'o', 'b', 'a'])).toBe('foobar') 6 | expect(prependArray('foobar')).toBe('foobar') 7 | expect(prependArray('', ['foobar'])).toBe('foobar') 8 | expect(prependArray('bar', ['foo'])).toBe('foobar') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/removeemptystrings.strman.test.js: -------------------------------------------------------------------------------- 1 | import { removeEmptyStrings } from '../src/strman' 2 | 3 | describe('strman.removeEmptyStrings', () => { 4 | test('should be [\'aa\', \'bb\', \'cc\' ]', () => { 5 | expect(removeEmptyStrings(['aa', '', 'bb', null, 'cc', undefined])).toMatchObject(['aa', 'bb', 'cc']) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /test/removeemptystrings.test.js: -------------------------------------------------------------------------------- 1 | import removeEmptyStrings from '../src/removeemptystrings' 2 | 3 | describe('strman.removeEmptyStrings', () => { 4 | test('should be [\'aa\', \'bb\', \'cc\' ]', () => { 5 | expect(removeEmptyStrings(['aa', '', 'bb', null, 'cc', undefined])).toMatchObject(['aa', 'bb', 'cc']) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /test/removeleft.strman.test.js: -------------------------------------------------------------------------------- 1 | import { removeLeft } from '../src/strman' 2 | 3 | describe('strman.removeLeft', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foobar', 'bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeLeft(el, 'foo')).toBe('bar') 9 | }) 10 | }) 11 | 12 | test('should be Foobar', () => { 13 | expect(removeLeft('Foobar', 'foo')).toBe('Foobar') 14 | }) 15 | 16 | test('should be bar', () => { 17 | expect(removeLeft('Foobar', 'foo', false)).toBe('bar') 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /test/removeleft.test.js: -------------------------------------------------------------------------------- 1 | import removeLeft from '../src/removeleft' 2 | 3 | describe('strman.removeLeft', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foobar', 'bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeLeft(el, 'foo')).toBe('bar') 9 | }) 10 | }) 11 | 12 | test('should be Foobar', () => { 13 | expect(removeLeft('Foobar', 'foo')).toBe('Foobar') 14 | }) 15 | 16 | test('should be bar', () => { 17 | expect(removeLeft('Foobar', 'foo', false)).toBe('bar') 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /test/removenonwords.strman.test.js: -------------------------------------------------------------------------------- 1 | import { removeNonWords } from '../src/strman' 2 | 3 | describe('strman.removeNonWords', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['foo bar', 'foo&bar-'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeNonWords(el)).toBe('foobar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/removenonwords.test.js: -------------------------------------------------------------------------------- 1 | import removeNonWords from '../src/removenonwords' 2 | 3 | describe('strman.removeNonWords', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['foo bar', 'foo&bar-'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeNonWords(el)).toBe('foobar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/removeright.strman.test.js: -------------------------------------------------------------------------------- 1 | import { removeRight } from '../src/strman' 2 | 3 | describe('strman.removeRight', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foobar', 'foo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeRight(el, 'bar')).toBe('foo') 9 | }) 10 | 11 | expect(removeRight('foofoofoobar', 'bar')).toBe('foofoofoo') 12 | expect(removeRight('foofoofoobar', 'foobar')).toBe('foofoo') 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /test/removeright.test.js: -------------------------------------------------------------------------------- 1 | import removeRight from '../src/removeright' 2 | 3 | describe('strman.removeRight', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foobar', 'foo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeRight(el, 'bar')).toBe('foo') 9 | }) 10 | 11 | expect(removeRight('foofoofoobar', 'bar')).toBe('foofoofoo') 12 | expect(removeRight('foofoofoobar', 'foobar')).toBe('foofoo') 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /test/removespaces.strman.test.js: -------------------------------------------------------------------------------- 1 | import { removeSpaces } from '../src/strman' 2 | 3 | describe('strman.removeSpaces', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeSpaces(el)).toBe('foobar') 9 | }) 10 | }) 11 | 12 | test('should be foo-bar', () => { 13 | const fixtures = ['foo bar'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(removeSpaces(el, '-')).toBe('foo-bar') 17 | }) 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /test/removespaces.test.js: -------------------------------------------------------------------------------- 1 | import removeSpaces from '../src/removespaces' 2 | 3 | describe('strman.removeSpaces', () => { 4 | test('should be foobar', () => { 5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(removeSpaces(el)).toBe('foobar') 9 | }) 10 | }) 11 | 12 | test('should be foo-bar', () => { 13 | const fixtures = ['foo bar'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(removeSpaces(el, '-')).toBe('foo-bar') 17 | }) 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /test/repeat.strman.test.js: -------------------------------------------------------------------------------- 1 | import { repeat } from '../src/strman' 2 | 3 | describe('strman.repeat', () => { 4 | test('should be 1 repeated', () => { 5 | expect(repeat('1', 1)).toBe('1') 6 | expect(repeat('1', 2)).toBe('11') 7 | expect(repeat('1', 3)).toBe('111') 8 | expect(repeat('1', 4)).toBe('1111') 9 | expect(repeat('1', 5)).toBe('11111') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/repeat.test.js: -------------------------------------------------------------------------------- 1 | import repeat from '../src/repeat' 2 | 3 | describe('strman.repeat', () => { 4 | test('should be 1 repeated', () => { 5 | expect(repeat('1', 1)).toBe('1') 6 | expect(repeat('1', 2)).toBe('11') 7 | expect(repeat('1', 3)).toBe('111') 8 | expect(repeat('1', 4)).toBe('1111') 9 | expect(repeat('1', 5)).toBe('11111') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/replace.strman.test.js: -------------------------------------------------------------------------------- 1 | import { replace } from '../src/strman' 2 | 3 | describe('strman.replace', () => { 4 | test('should be bar bar', () => { 5 | const fixtures = ['foo bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(replace(el, 'foo', 'bar')).toBe('bar bar') 9 | }) 10 | }) 11 | test('should be bar bar bar', () => { 12 | const fixtures = ['foo bar foo'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(replace(el, 'foo', 'bar')).toBe('bar bar bar') 16 | }) 17 | }) 18 | }) 19 | 20 | describe('strman.replace - caseSensitive', () => { 21 | test('should be bar bar', () => { 22 | const fixtures = ['FOO bar'] 23 | 24 | fixtures.forEach((el) => { 25 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar') 26 | }) 27 | }) 28 | test('should be bar bar bar', () => { 29 | const fixtures = ['FOO bar foo'] 30 | 31 | fixtures.forEach((el) => { 32 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar bar') 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /test/replace.test.js: -------------------------------------------------------------------------------- 1 | import replace from '../src/replace' 2 | 3 | describe('strman.replace', () => { 4 | test('should be bar bar', () => { 5 | const fixtures = ['foo bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(replace(el, 'foo', 'bar')).toBe('bar bar') 9 | }) 10 | }) 11 | test('should be bar bar bar', () => { 12 | const fixtures = ['foo bar foo'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(replace(el, 'foo', 'bar')).toBe('bar bar bar') 16 | }) 17 | }) 18 | }) 19 | 20 | describe('strman.replace - caseSensitive', () => { 21 | test('should be bar bar', () => { 22 | const fixtures = ['FOO bar'] 23 | 24 | fixtures.forEach((el) => { 25 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar') 26 | }) 27 | }) 28 | test('should be bar bar bar', () => { 29 | const fixtures = ['FOO bar foo'] 30 | 31 | fixtures.forEach((el) => { 32 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar bar') 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /test/reverse.strman.test.js: -------------------------------------------------------------------------------- 1 | import { reverse } from '../src/strman' 2 | 3 | describe('strman.reverse', () => { 4 | test('should be strings reverse', () => { 5 | expect(reverse('foo')).toBe('oof') 6 | expect(reverse('daniel')).toBe('leinad') 7 | expect(reverse('')).toBe('') 8 | expect(reverse('bar')).toBe('rab') 9 | expect(reverse('foo_')).toBe('_oof') 10 | expect(reverse('f')).toBe('f') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/reverse.test.js: -------------------------------------------------------------------------------- 1 | import reverse from '../src/reverse' 2 | 3 | describe('strman.reverse', () => { 4 | test('should be strings reverse', () => { 5 | expect(reverse('foo')).toBe('oof') 6 | expect(reverse('daniel')).toBe('leinad') 7 | expect(reverse('')).toBe('') 8 | expect(reverse('bar')).toBe('rab') 9 | expect(reverse('foo_')).toBe('_oof') 10 | expect(reverse('f')).toBe('f') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/rightpad.strman.test.js: -------------------------------------------------------------------------------- 1 | import { rightPad } from '../src/strman' 2 | 3 | describe('strman.rightPad', () => { 4 | test('should be 10000', () => { 5 | expect(rightPad('1', 5, '00')).toBe('10000') 6 | expect(rightPad('1', 5, 0)).toBe('10000') 7 | expect(rightPad('10', 5, 0)).toBe('10000') 8 | expect(rightPad('100', 5, 0)).toBe('10000') 9 | expect(rightPad('1000', 5, 0)).toBe('10000') 10 | expect(rightPad('10000', 5, 0)).toBe('10000') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/rightpad.test.js: -------------------------------------------------------------------------------- 1 | import rightPad from '../src/rightpad' 2 | 3 | describe('strman.rightPad', () => { 4 | test('should be 10000', () => { 5 | expect(rightPad('1', 5, '00')).toBe('10000') 6 | expect(rightPad('1', 5, 0)).toBe('10000') 7 | expect(rightPad('10', 5, 0)).toBe('10000') 8 | expect(rightPad('100', 5, 0)).toBe('10000') 9 | expect(rightPad('1000', 5, 0)).toBe('10000') 10 | expect(rightPad('10000', 5, 0)).toBe('10000') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/righttrim.strman.test.js: -------------------------------------------------------------------------------- 1 | import { rightTrim } from '../src/strman' 2 | 3 | describe('strman.rightTrim', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = [' foo bar', ' foo bar ', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(rightTrim(el)).toBe(' foo bar') 9 | }) 10 | }) 11 | 12 | test('should be foo bar without @', () => { 13 | const fixtures = ['foo bar@', 'foo bar@@@@@'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(rightTrim(el, '@')).toBe('foo bar') 17 | }) 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /test/righttrim.test.js: -------------------------------------------------------------------------------- 1 | import righttrim from '../src/righttrim' 2 | 3 | describe('strman.righttrim', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = [' foo bar', ' foo bar ', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(righttrim(el)).toBe(' foo bar') 9 | }) 10 | }) 11 | 12 | test('should be foo bar without @', () => { 13 | const fixtures = ['foo bar@', 'foo bar@@@@@'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(righttrim(el, '@')).toBe('foo bar') 17 | }) 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /test/safetruncate.strman.test.js: -------------------------------------------------------------------------------- 1 | import { safeTruncate } from '../src/strman' 2 | 3 | describe('strman.safeTruncate', () => { 4 | test('should be strings safeTruncated', () => { 5 | expect(safeTruncate('foo bar', 0, '.')).toBe('') 6 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.') 7 | expect(safeTruncate('foo bar', 3, '.')).toBe('.') 8 | expect(safeTruncate('foo bar', 2, '.')).toBe('.') 9 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.') 10 | expect(safeTruncate('foo bar', 7, '.')).toBe('foo bar') 11 | expect(safeTruncate('foo bar', 8, '.')).toBe('foo bar') 12 | expect(safeTruncate('A Javascript string manipulation library.', 16, '...')).toBe('A Javascript...') 13 | expect(safeTruncate('A Javascript string manipulation library.', 15, '...')).toBe('A Javascript...') 14 | expect(safeTruncate('A Javascript string manipulation library.', 14, '...')).toBe('A...') 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /test/safetruncate.test.js: -------------------------------------------------------------------------------- 1 | import safeTruncate from '../src/safetruncate' 2 | 3 | describe('strman.safeTruncate', () => { 4 | test('should be strings safeTruncated', () => { 5 | expect(safeTruncate('foo bar', 0, '.')).toBe('') 6 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.') 7 | expect(safeTruncate('foo bar', 3, '.')).toBe('.') 8 | expect(safeTruncate('foo bar', 2, '.')).toBe('.') 9 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.') 10 | expect(safeTruncate('foo bar', 7, '.')).toBe('foo bar') 11 | expect(safeTruncate('foo bar', 8, '.')).toBe('foo bar') 12 | expect(safeTruncate('A Javascript string manipulation library.', 16, '...')).toBe('A Javascript...') 13 | expect(safeTruncate('A Javascript string manipulation library.', 15, '...')).toBe('A Javascript...') 14 | expect(safeTruncate('A Javascript string manipulation library.', 14, '...')).toBe('A...') 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /test/shuffle.strman.test.js: -------------------------------------------------------------------------------- 1 | import { shuffle } from '../src/strman' 2 | 3 | describe('strman.shuffle', () => { 4 | test('should be strings shuffle', () => { 5 | expect(shuffle('foo').length).toBe(3) 6 | expect(shuffle('daniel').length).toBe(6) 7 | expect(shuffle('')).toBe('') 8 | expect(shuffle('b')).toBe('b') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/shuffle.test.js: -------------------------------------------------------------------------------- 1 | import shuffle from '../src/shuffle' 2 | 3 | describe('strman.shuffle', () => { 4 | test('should be strings shuffle', () => { 5 | expect(shuffle('foo').length).toBe(3) 6 | expect(shuffle('daniel').length).toBe(6) 7 | expect(shuffle('')).toBe('') 8 | expect(shuffle('b')).toBe('b') 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/slice.strman.test.js: -------------------------------------------------------------------------------- 1 | import { slice } from '../src/strman' 2 | 3 | describe('strman.slice', () => { 4 | test('should be foobar', () => { 5 | expect(slice('foobar', 0, 6)).toBe('foobar') 6 | expect(slice('foobar', 1, 5)).toBe('ooba') 7 | expect(slice('foobar', 2, 4)).toBe('ob') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/slice.test.js: -------------------------------------------------------------------------------- 1 | import slice from '../src/slice' 2 | 3 | describe('strman.slice', () => { 4 | test('should be foobar', () => { 5 | expect(slice('foobar', 0, 6)).toBe('foobar') 6 | expect(slice('foobar', 1, 5)).toBe('ooba') 7 | expect(slice('foobar', 2, 4)).toBe('ob') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/slugify.strman.test.js: -------------------------------------------------------------------------------- 1 | import { slugify } from '../src/strman' 2 | 3 | describe('strman.slugfiy', () => { 4 | test('should be foo-bar', () => { 5 | const fixtures = ['foo bar', 'foo bar.', 'foo bar ', ' foo bar', ' foo bar ', 'foo------bar', 'fóõ bár', 'foo ! bar', 'foo ~~ bar', 'foo bar', 'FOO bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(slugify(el)).toBe('foo-bar') 9 | }) 10 | }) 11 | test('should be foo-and-bar', () => { 12 | const fixtures = ['foo&bar', 'foo&bar.', 'foo&bar ', ' foo&bar', ' foo&bar ', 'foo&bar', 'fóõ-and---bár', 'foo & bar', 'FOO & bar'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(slugify(el)).toBe('foo-and-bar') 16 | }) 17 | }) 18 | 19 | test('should be throw', () => { 20 | const fixtures = [1, [], {}, 1.2, false, true] 21 | 22 | fixtures.forEach((el) => { 23 | expect(() => { 24 | slugify(el) 25 | }).toThrow(Error) 26 | }) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /test/slugify.test.js: -------------------------------------------------------------------------------- 1 | import slugify from '../src/slugify' 2 | 3 | describe('strman.slugfiy', () => { 4 | test('should be foo-bar', () => { 5 | const fixtures = ['foo bar', 'foo bar.', 'foo bar ', 'foo bar .', ' foo bar', ' foo bar ', 'foo------bar', 'fóõ bár', 'foo ! bar', 'foo ~~ bar', 'foo bar', 'FOO bar'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(slugify(el)).toBe('foo-bar') 9 | }) 10 | }) 11 | test('should be foo-and-bar', () => { 12 | const fixtures = ['foo&bar', 'foo&bar.', 'foo&bar ', ' foo&bar', ' foo&bar ', 'foo&bar', 'fóõ-and---bár', 'foo & bar', 'FOO & bar'] 13 | 14 | fixtures.forEach((el) => { 15 | expect(slugify(el)).toBe('foo-and-bar') 16 | }) 17 | }) 18 | 19 | test('should be throw', () => { 20 | const fixtures = [1, [], {}, 1.2, false, true] 21 | 22 | fixtures.forEach((el) => { 23 | expect(() => { 24 | slugify(el) 25 | }).toThrow(Error) 26 | }) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /test/split.strman.test.js: -------------------------------------------------------------------------------- 1 | import { split } from '../src/strman' 2 | 3 | describe('strman.split', () => { 4 | test('should be [f o o]', () => { 5 | expect(split('foo')).toEqual(['f', 'o', 'o']) 6 | }) 7 | test('should be [f o]', () => { 8 | expect(split('foo', '', 2)).toEqual(['f', 'o']) 9 | }) 10 | test('should be [foo bar]', () => { 11 | expect(split('foo bar', ' ')).toEqual(['foo', 'bar']) 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /test/split.test.js: -------------------------------------------------------------------------------- 1 | import split from '../src/split' 2 | 3 | describe('strman.split', () => { 4 | test('should be [f o o]', () => { 5 | expect(split('foo')).toEqual(['f', 'o', 'o']) 6 | }) 7 | test('should be [f o]', () => { 8 | expect(split('foo', '', 2)).toEqual(['f', 'o']) 9 | }) 10 | test('should be [foo bar]', () => { 11 | expect(split('foo bar', ' ')).toEqual(['foo', 'bar']) 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /test/startswith.strman.test.js: -------------------------------------------------------------------------------- 1 | import { startsWith } from '../src/strman' 2 | 3 | describe('strman.startsWith', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foo bar', 'foobar', 'foo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(startsWith(el, 'foo')).toBe(true) 9 | }) 10 | 11 | const fixtures2 = ['afoo barr', 'afoo'] 12 | 13 | fixtures2.forEach((el) => { 14 | expect(startsWith(el, 'foo', 1)).toBe(true) 15 | }) 16 | }) 17 | }) 18 | 19 | describe('strman.startsWith caseSensitive', () => { 20 | test('should be true', () => { 21 | const fixtures = ['foo bar', 'foobar', 'foo'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(startsWith(el, 'FOO', 0, false)).toBe(true) 25 | }) 26 | 27 | const fixtures2 = ['afoo barr', 'afoo'] 28 | 29 | fixtures2.forEach((el) => { 30 | expect(startsWith(el, 'FOO', 1, false)).toBe(true) 31 | }) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /test/startswith.test.js: -------------------------------------------------------------------------------- 1 | import startsWith from '../src/startswith' 2 | 3 | describe('strman.startsWith', () => { 4 | test('should be true', () => { 5 | const fixtures = ['foo bar', 'foobar', 'foo'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(startsWith(el, 'foo')).toBe(true) 9 | }) 10 | 11 | const fixtures2 = ['afoo barr', 'afoo'] 12 | 13 | fixtures2.forEach((el) => { 14 | expect(startsWith(el, 'foo', 1)).toBe(true) 15 | }) 16 | }) 17 | }) 18 | 19 | describe('strman.startsWith caseSensitive', () => { 20 | test('should be true', () => { 21 | const fixtures = ['foo bar', 'foobar', 'foo'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(startsWith(el, 'FOO', 0, false)).toBe(true) 25 | }) 26 | 27 | const fixtures2 = ['afoo barr', 'afoo'] 28 | 29 | fixtures2.forEach((el) => { 30 | expect(startsWith(el, 'FOO', 1, false)).toBe(true) 31 | }) 32 | }) 33 | }) 34 | -------------------------------------------------------------------------------- /test/surround.strman.test.js: -------------------------------------------------------------------------------- 1 | import { surround } from '../src/strman' 2 | 3 | describe('strman.surround', () => { 4 | test('should be strings surround', () => { 5 | expect(surround('foo', 'bar')).toBe('barfoobar') 6 | expect(surround('daniel', '_')).toBe('_daniel_') 7 | expect(surround('', '>')).toBe('>>') 8 | expect(surround('bar', '')).toBe('bar') 9 | expect(surround('f')).toBe('f') 10 | expect(surround('div', '<', '>')).toBe('
') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/surround.test.js: -------------------------------------------------------------------------------- 1 | import surround from '../src/surround' 2 | 3 | describe('strman.surround', () => { 4 | test('should be strings surround', () => { 5 | expect(surround('foo', 'bar')).toBe('barfoobar') 6 | expect(surround('daniel', '_')).toBe('_daniel_') 7 | expect(surround('', '>')).toBe('>>') 8 | expect(surround('bar', '')).toBe('bar') 9 | expect(surround('f')).toBe('f') 10 | expect(surround('div', '<', '>')).toBe('
') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/tocamelcase.strman.test.js: -------------------------------------------------------------------------------- 1 | import { toCamelCase } from '../src/strman' 2 | 3 | describe('strman.toCamelCase', () => { 4 | test('should match camelCase', () => { 5 | const fixtures = ['CamelCase', 'camelCase', 'Camel case', 'Camel case', 'camel Case', 'camel-case', '-camel--case', 'camel_case', ' camel_case'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(toCamelCase(el)).toBe('camelCase') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/tocamelcase.test.js: -------------------------------------------------------------------------------- 1 | import toCamelCase from '../src/tocamelcase' 2 | 3 | describe('strman.toCamelCase', () => { 4 | test('should match camelCase', () => { 5 | const fixtures = ['CamelCase', 'camelCase', 'Camel case', 'Camel case', 'camel Case', 'camel-case', '-camel--case', 'camel_case', ' camel_case'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(toCamelCase(el)).toBe('camelCase') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/tokebabcase.strman.test.js: -------------------------------------------------------------------------------- 1 | import { toKebabCase } from '../src/strman' 2 | 3 | describe('strman.toKebabCase', () => { 4 | test('should match de_camelize', () => { 5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(toKebabCase(el)).toBe('de-camelize') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/tokebabcase.test.js: -------------------------------------------------------------------------------- 1 | import toKebabCase from '../src/tokebabcase' 2 | 3 | describe('strman.toKebabCase', () => { 4 | test('should match de_camelize', () => { 5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(toKebabCase(el)).toBe('de-camelize') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/tosnakecase.strman.test.js: -------------------------------------------------------------------------------- 1 | import { toSnakeCase } from '../src/strman' 2 | 3 | describe('strman.toSnakeCase', () => { 4 | test('should match de_camelize', () => { 5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(toSnakeCase(el)).toBe('de_camelize') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/tosnakecase.test.js: -------------------------------------------------------------------------------- 1 | import toSnakeCase from '../src/tosnakecase' 2 | 3 | describe('strman.toSnakeCase', () => { 4 | test('should match de_camelize', () => { 5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(toSnakeCase(el)).toBe('de_camelize') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/tostudlycaps.strman.test.js: -------------------------------------------------------------------------------- 1 | import { toStudlyCaps } from '../src/strman' 2 | 3 | describe('strman.toStudlyCaps', () => { 4 | test('should match DeCamelize', () => { 5 | const fixtures = [ 6 | 'deCamelize', 7 | 'de-Camelize', 8 | 'de camelize', 9 | 'de camelize', 10 | 'de Camelize', 11 | 'de-camelize', 12 | '-de--camelize', 13 | 'de_camelize', 14 | ' de_camelize', 15 | ] 16 | 17 | fixtures.forEach((el) => { 18 | expect(toStudlyCaps(el)).toBe('DeCamelize') 19 | }) 20 | }) 21 | test('should match DeCamelize', () => { 22 | const fixtures = [ 23 | ` 24 | 1`, 25 | ] 26 | 27 | fixtures.forEach((el) => { 28 | expect(toStudlyCaps(el)).toBe('1') 29 | }) 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /test/tostudlycaps.test.js: -------------------------------------------------------------------------------- 1 | import toStudlyCaps from '../src/tostudlycaps' 2 | 3 | describe('strman.toStudlyCaps', () => { 4 | test('should match DeCamelize', () => { 5 | const fixtures = [ 6 | 'deCamelize', 7 | 'de-Camelize', 8 | 'de camelize', 9 | 'de camelize', 10 | 'de Camelize', 11 | 'de-camelize', 12 | '-de--camelize', 13 | 'de_camelize', 14 | ' de_camelize', 15 | ] 16 | 17 | fixtures.forEach((el) => { 18 | expect(toStudlyCaps(el)).toBe('DeCamelize') 19 | }) 20 | }) 21 | test('should match DeCamelize', () => { 22 | const fixtures = [ 23 | ` 24 | 1`, 25 | ] 26 | 27 | fixtures.forEach((el) => { 28 | expect(toStudlyCaps(el)).toBe('1') 29 | }) 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /test/transliterate.strman.test.js: -------------------------------------------------------------------------------- 1 | import { transliterate } from '../src/strman' 2 | 3 | describe('strman.transliterate', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['fóõ bár'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(transliterate(el)).toBe('foo bar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/transliterate.test.js: -------------------------------------------------------------------------------- 1 | import transliterate from '../src/transliterate' 2 | 3 | describe('strman.transliterate', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['fóõ bár'] 6 | 7 | fixtures.forEach((el) => { 8 | expect(transliterate(el)).toBe('foo bar') 9 | }) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/trim.strman.test.js: -------------------------------------------------------------------------------- 1 | import { trim } from '../src/strman' 2 | 3 | describe('strman.trim', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(trim(el)).toBe('foo bar') 9 | }) 10 | }) 11 | 12 | test('should be foo bar without @', () => { 13 | const fixtures = ['foo bar', 'foo bar@', '@foo bar', '@@foo bar@@@'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(trim(el, '@')).toBe('foo bar') 17 | }) 18 | }) 19 | 20 | test('should be foo bar without @ and with #', () => { 21 | const fixtures = ['@#foo bar', '#foo bar@', '@#foo bar@', '@@#foo bar@@@'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(trim(el, '@')).toBe('#foo bar') 25 | }) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/trim.test.js: -------------------------------------------------------------------------------- 1 | import trim from '../src/trim' 2 | 3 | describe('strman.trim', () => { 4 | test('should be foo bar', () => { 5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar '] 6 | 7 | fixtures.forEach((el) => { 8 | expect(trim(el)).toBe('foo bar') 9 | }) 10 | }) 11 | 12 | test('should be foo bar without @', () => { 13 | const fixtures = ['foo bar', 'foo bar@', '@foo bar', '@@foo bar@@@'] 14 | 15 | fixtures.forEach((el) => { 16 | expect(trim(el, '@')).toBe('foo bar') 17 | }) 18 | }) 19 | 20 | test('should be foo bar without @ and with #', () => { 21 | const fixtures = ['@#foo bar', '#foo bar@', '@#foo bar@', '@@#foo bar@@@'] 22 | 23 | fixtures.forEach((el) => { 24 | expect(trim(el, '@')).toBe('#foo bar') 25 | }) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /test/truncate.strman.test.js: -------------------------------------------------------------------------------- 1 | import { truncate } from '../src/strman' 2 | 3 | describe('strman.truncate', () => { 4 | test('should be strings truncated', () => { 5 | expect(truncate('foo bar', 0, '.')).toBe('') 6 | expect(truncate('foo bar', 3, '.')).toBe('fo.') 7 | expect(truncate('foo bar', 2, '.')).toBe('f.') 8 | expect(truncate('foo bar', 4, '.')).toBe('foo.') 9 | expect(truncate('foo bar', 7, '.')).toBe('foo bar') 10 | expect(truncate('foo bar', 8, '.')).toBe('foo bar') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/truncate.test.js: -------------------------------------------------------------------------------- 1 | import truncate from '../src/truncate' 2 | 3 | describe('strman.truncate', () => { 4 | test('should be strings truncated', () => { 5 | expect(truncate('foo bar', 0, '.')).toBe('') 6 | expect(truncate('foo bar', 3, '.')).toBe('fo.') 7 | expect(truncate('foo bar', 2, '.')).toBe('f.') 8 | expect(truncate('foo bar', 4, '.')).toBe('foo.') 9 | expect(truncate('foo bar', 7, '.')).toBe('foo bar') 10 | expect(truncate('foo bar', 8, '.')).toBe('foo bar') 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/urldecode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { urlDecode } from '../src/strman' 2 | 3 | describe('strman.slice', () => { 4 | test('should be foobar', () => { 5 | expect(urlDecode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/') 6 | expect(urlDecode('https://web.whatsapp.com/?text=%20a')).toBe('https://web.whatsapp.com/?text= a') 7 | expect(urlDecode('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')).toBe('https://web.whatsapp.com/?text=áéíóú') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/urldecode.test.js: -------------------------------------------------------------------------------- 1 | import urlDecode from '../src/urlDecode' 2 | 3 | describe('strman.slice', () => { 4 | test('should be foobar', () => { 5 | expect(urlDecode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/') 6 | expect(urlDecode('https://web.whatsapp.com/?text=%20a')).toBe('https://web.whatsapp.com/?text= a') 7 | expect(urlDecode('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')).toBe('https://web.whatsapp.com/?text=áéíóú') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/urlencode.strman.test.js: -------------------------------------------------------------------------------- 1 | import { urlEncode } from '../src/strman' 2 | 3 | describe('strman.slice', () => { 4 | test('should be foobar', () => { 5 | expect(urlEncode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/') 6 | expect(urlEncode('https://web.whatsapp.com/?text=áéíóú')).toBe('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA') 7 | expect(urlEncode('https://web.whatsapp.com/?text= a')).toBe('https://web.whatsapp.com/?text=%20a') 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /test/urlencode.test.js: -------------------------------------------------------------------------------- 1 | import urlEncode from '../src/urlencode' 2 | 3 | describe('strman.slice', () => { 4 | test('should be foobar', () => { 5 | expect(urlEncode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/') 6 | expect(urlEncode('https://web.whatsapp.com/?text=áéíóú')).toBe('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA') 7 | expect(urlEncode('https://web.whatsapp.com/?text= a')).toBe('https://web.whatsapp.com/?text=%20a') 8 | }) 9 | }) 10 | --------------------------------------------------------------------------------