Repository: plexis-js/plexis
Pull request #89 (2019-10-27 22:34:24)

Added package toSwap
I wasn't able to get the toSwap function to work once I added it to index.js in the plexis folder. I checked the instructions but I wasn't missing anything. I don't really know why it's not working. It is set up exactly like every other function.

The function itself works, and has 5 test cases, testing different possible entries that might have not been accounted for. These test cases also run, the only one that doesn't is in plexis/test/index.js. 

For some reason, it cannot find the toSwap function.

Fixes Issue #75 

codecov[bot]: # [Codecov](https://codecov.io/gh/plexis-js/plexis/pull/89?src=pr&el=h1) Report
> Merging [#89](https://codecov.io/gh/plexis-js/plexis/pull/89?src=pr&el=desc) into [master](https://codecov.io/gh/plexis-js/plexis/commit/6e51bfb92a4d8c9a0ef3bc090a43c09b7da14cf7?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.


[![Impacted file tree graph](https://codecov.io/gh/plexis-js/plexis/pull/89/graphs/tree.svg?width=650&token=DdDVC9ByG1&height=150&src=pr)](https://codecov.io/gh/plexis-js/plexis/pull/89?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master    #89   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          26     27    +1     
  Lines         130    137    +7     
=====================================
+ Hits          130    137    +7
```


| [Impacted Files](https://codecov.io/gh/plexis-js/plexis/pull/89?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/toSwap/src/index.js](https://codecov.io/gh/plexis-js/plexis/pull/89/diff?src=pr&el=tree#diff-cGFja2FnZXMvdG9Td2FwL3NyYy9pbmRleC5qcw==) | `100% <100%> (ø)` | |

drwm-base: I know what the problem is, I was missing the dist folder.
brandon-m-skinner: Hi @drwm-base 

You're missing the entry into docs/pages/api.md for your new package.

Brandon 

drwm-base: Thanks for the reminder, almost missed that!
drwm-base: @vorillaz @brandon-m-skinner I added toSwap to the API. Is there anything else that I can do?
drwm-base: @brandon-m-skinner I have updated to the most recent version, please let me know if there is anything I need to fix!

Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index 56c357b..1628043 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -33,3 +33,4 @@
 - [withoutHTML](/packages/withoutHTML)
 - [withoutIndent](/packages/withoutIndent)
 - [tail](/packages/tail)
+- [toSwap](/packages/toSwap)
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index b5e53ef..edd43fe 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -41,6 +41,7 @@
     "@plexis/to-title": "^0.0.21",
     "@plexis/when": "^0.0.21",
     "@plexis/without-diacritics": "^0.0.21",
+    "@plexis/to-swap": "^0.0.21",
     "@plexis/without-html": "^0.0.21",
     "@plexis/without-indent": "^0.0.21",
     "@plexis/tail": "^0.0.21"
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index 604cc1e..6124521 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -66,3 +66,4 @@ export {
 } from '@plexis/is-alphanumeric';
 export {default as withoutHTML, default as removeHTML} from '@plexis/without-html';
 export {default as tail, default as rest, default as last, default as pop} from '@plexis/tail';
+export {default as toSwap, default as swap} from '@plexis/to-swap';
diff --git a/packages/toSwap/README.md b/packages/toSwap/README.md
new file mode 100644
index 0000000..537f228
--- /dev/null
+++ b/packages/toSwap/README.md
@@ -0,0 +1,23 @@
+## `@plexis/toSwap`
+
+Swaps every character with the next one in a given string.
+
+`npm i @plexis/to-swap`
+
+**Usage**
+
+```javascript
+import toSwap from '@plexis/to-swap';
+
+toSwap('ab'); // returns 'ba'
+toSwap('abc'); // returns 'bac'
+toSwap('abcd'); // returns 'badc'
+toSwap('a b'); // returns ' ab'
+```
+
+**Aliases**
+
+```javascript
+import {toSwap} from 'plexis';
+import {swap} from 'plexis';
+```
diff --git a/packages/toSwap/package.json b/packages/toSwap/package.json
new file mode 100644
index 0000000..cdc57af
--- /dev/null
+++ b/packages/toSwap/package.json
@@ -0,0 +1,29 @@
+{
+  "name": "@plexis/to-swap",
+  "version": "0.0.21",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "files": [
+    "dist",
+    "src"
+  ],
+  "authors": [
+    "David Medeiros <david.medeiros@live.com>"
+  ],
+  "license": "MIT",
+  "keywords": [
+    "utility",
+    "string",
+    "parse",
+    "format",
+    "validate"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  }
+}
diff --git a/packages/toSwap/src/index.js b/packages/toSwap/src/index.js
new file mode 100644
index 0000000..b6679c8
--- /dev/null
+++ b/packages/toSwap/src/index.js
@@ -0,0 +1,21 @@
+/**
+ * @description Swaps every character in a string, until the end of the string
+ * @param {String} string
+ * @example
+ * toSwap('ab') // returns 'ab'
+ * toSwap('a b') // returns ' ab'
+ * toSwap('abcd') // returns 'badc'
+ * @returns {String} reordered letters
+ */
+const toSwap = string => {
+  var arr = string.split('');
+  arr.forEach((current, index, array) => {
+    if (index % 2 == 0) {
+      array[index] = array[index + 1];
+      array[index + 1] = current;
+    }
+  });
+  return arr.join('');
+};
+
+export default toSwap;


Test patch:
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index dc1e65d..04566a0 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -71,5 +71,7 @@ Array [
   "rest",
   "last",
   "pop",
+  "toSwap",
+  "swap",
 ]
 `;
diff --git a/packages/toSwap/test/index.js b/packages/toSwap/test/index.js
new file mode 100644
index 0000000..bc6ab57
--- /dev/null
+++ b/packages/toSwap/test/index.js
@@ -0,0 +1,21 @@
+import toSwap from '../src';
+
+it('Swap only small strings', () => {
+  expect(toSwap('ab')).toBe('ba');
+  expect(toSwap('a')).toBe('a');
+});
+it('Swap an odd number of letters', () => {
+  expect(toSwap('abc')).toBe('bac');
+  expect(toSwap('abcd')).toBe('badc');
+});
+it('Swap with spaces', () => {
+  expect(toSwap('a b')).toBe(' ab');
+  expect(toSwap('ab cd')).toBe('bac d');
+});
+it('Swap Random Characters', () => {
+  expect(toSwap('1;3')).toBe(';13');
+  expect(toSwap('.,][')).toBe(',.[]');
+});
+it('Empty string case', () => {
+  expect(toSwap('')).toBe('');
+});