Repository: plexis-js/plexis (js)

Issue:
Feature request:  `toTurabian/ toChicagoManualStyle/ toChicagoStyle`
A method that transforms text according to [Turabian / Chicago Style](https://cmosshoptalk.com/2018/11/13/how-do-i-format-main-text-in-turabian-chicago-style/) format.

```javascript
@param {String} [txt] The text to transform
@returns {String} Returns text transformed according to the The Chicago Manual of Style.
```

**Example usage**

```javascript
import toChicago from '@plexis/to-chicago';
toChicago('This is a title'); // returns 'This Is a Title'
toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.'
toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case'
```

**Aliases**

```javascript
import toChicago from '@plexis/to-chicago';
import {toTurabian, toChicagoManualStyle, toChicagoStyle, toChicagoTitle } from 'plexis'
```


Pull request description:
Add `toChicago`
- Resolve #4 

Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index 4ececb0..3c4e538 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -3,6 +3,7 @@
 - [compose](/packages/compose)
 - [isLowerCase](/packages/isLowerCase)
 - [isUpperCase](/packages/isUpperCase)
+- [toChicago](/packages/toChicago)
 - [toLower](/packages/toLower)
 - [toPred](/packages/toPred)
 - [toSucc](/packages/toSucc)
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index e927eb4..201b0ac 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -12,6 +12,7 @@
     "@plexis/compose": "^0.0.13",
     "@plexis/is-lowercase": "^0.0.13",
     "@plexis/is-uppercase": "^0.0.13",
+    "@plexis/to-chicago": "^0.0.13",
     "@plexis/to-lower": "^0.0.13",
     "@plexis/to-pred": "^0.0.13",
     "@plexis/to-succ": "^0.0.13",
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index e195599..822fc15 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -13,4 +13,10 @@ export {
 } from '@plexis/without-diacritics';
 export {default as isLowerCase, default as isLower} from '@plexis/is-lowercase';
 export {default as isUpperCase, default as isUpper} from '@plexis/is-uppercase';
-export {default as compose, default as _do} from '@plexis/compose';
\ No newline at end of file
+export {default as compose, default as _do} from '@plexis/compose';
+export {
+  default as toTurabian,
+  default as toChicagoManualStyle,
+  default as toChicagoStyle,
+  default as toChicagoTitle
+} from '@plexis/to-chicago';
diff --git a/packages/toChicago/.npmignore b/packages/toChicago/.npmignore
new file mode 100644
index 0000000..552cf85
--- /dev/null
+++ b/packages/toChicago/.npmignore
@@ -0,0 +1,17 @@
+.DS_Store
+*.test.js
+.prettierrc
+.github
+.template
+.package-template
+.nyc_output
+.circleci
+.commitlintrc.js
+coverage
+coverage.lcov
+docs
+babel.config.js
+test
+CONTRIBUTING.md
+CODE_OF_CONDUCT.md
+LICENCE
\ No newline at end of file
diff --git a/packages/toChicago/README.md b/packages/toChicago/README.md
new file mode 100644
index 0000000..93e5674
--- /dev/null
+++ b/packages/toChicago/README.md
@@ -0,0 +1,22 @@
+## `@plexis/to-chicago`
+
+Convert text into Chicago style
+
+`npm i @plexis/to-chicago`
+
+**Usage**
+
+```javascript
+import toChicago from '@plexis/to-chicago';
+
+toChicago('This is a title'); // returns 'This Is a Title'
+toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.'
+toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case'
+```
+
+**Aliases**
+
+```javascript
+import toChicago from '@plexis/to-chicago';
+import {toTurabian, toChicagoManualStyle, toChicagoStyle, toChicagoTitle} from 'plexis';
+```
diff --git a/packages/toChicago/package.json b/packages/toChicago/package.json
new file mode 100644
index 0000000..9daa551
--- /dev/null
+++ b/packages/toChicago/package.json
@@ -0,0 +1,24 @@
+{
+  "name": "@plexis/to-chicago",
+  "version": "0.0.13",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "authors": [
+    "Nguyễn Tuấn Dũng <ntddebugger@gmail.com>"
+  ],
+  "license": "MIT",
+  "keywords": [
+    "utility",
+    "string",
+    "parse",
+    "format"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  }
+}
\ No newline at end of file
diff --git a/packages/toChicago/src/index.js b/packages/toChicago/src/index.js
new file mode 100644
index 0000000..56c1dea
--- /dev/null
+++ b/packages/toChicago/src/index.js
@@ -0,0 +1,116 @@
+const formatWord = word =>
+  word
+    .split('-')
+    .map(s => s.charAt(0).toUpperCase() + s.toLowerCase().substring(1))
+    .join('-');
+
+// Prepositions list
+const wordException = [
+  'a',
+  'an',
+  'the',
+  'and',
+  'or',
+  'aboard',
+  'about',
+  'above',
+  'across',
+  'after',
+  'against',
+  'along',
+  'amid',
+  'among',
+  'around',
+  'as',
+  'at',
+  'before',
+  'behind',
+  'below',
+  'beneath',
+  'beside',
+  'between',
+  'beyond',
+  'but',
+  'by',
+  'concerning',
+  'considering',
+  'despite',
+  'down',
+  'during',
+  'except',
+  'following',
+  'for',
+  'from',
+  'in',
+  'inside',
+  'into',
+  'like',
+  'minus',
+  'near',
+  'next',
+  'of',
+  'off',
+  'on',
+  'onto',
+  'opposite',
+  'out',
+  'outside',
+  'over',
+  'past',
+  'per',
+  'plus',
+  'regarding',
+  'round',
+  'save',
+  'since',
+  'than',
+  'through',
+  'to',
+  'toward',
+  'under',
+  'underneath',
+  'unlike',
+  'until',
+  'up',
+  'upon',
+  'versus',
+  'via',
+  'with',
+  'within',
+  'without'
+];
+
+const formatSentence = sentence =>
+  sentence
+    .trim()
+    .split(/\s+/)
+    .map((word, index) =>
+      index > 0 && wordException.includes(word.toLowerCase())
+        ? word.toLowerCase()
+        : formatWord(word)
+    )
+    .join(' ');
+
+/**
+ * @description Convert text into Chicago style
+ * @param {String} text The text to transform
+ * @returns {String} Returns text transformed according to the The Chicago Manual of Style.
+ * @example
+ * toChicago('This is a title'); // returns 'This Is a Title'
+ * toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.'
+ * toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case'
+ 
+ */
+const toChicago = text =>
+  text
+    .replace(/\s+/, ' ')
+    .replace(/\s+([.?!,:;])\s*/, '$1 ')
+    .concat('.')
+    .match(/(.*?)([.?!])/g)
+    .map(sentence => sentence.match(/(.*?)([.?!])/))
+    .map(x => formatSentence(x[1]) + x[2])
+    .join(' ')
+    .slice(0, -1)
+    .trimRight();
+
+export default toChicago;


Test patch:
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index 0dd186c..70fb638 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -21,5 +21,9 @@ Array [
   "isUpper",
   "compose",
   "_do",
+  "toTurabian",
+  "toChicagoManualStyle",
+  "toChicagoStyle",
+  "toChicagoTitle",
 ]
 `;
diff --git a/packages/toChicago/test/index.js b/packages/toChicago/test/index.js
new file mode 100644
index 0000000..04eaae5
--- /dev/null
+++ b/packages/toChicago/test/index.js
@@ -0,0 +1,17 @@
+import toChicago from '../src';
+
+it('transform normal string', () => {
+  expect(toChicago('This is a title')).toBe('This Is a Title');
+});
+
+it('transform mixed sentence', () => {
+  expect(toChicago('in Turabian shows a sample title page for a class paper.')).toBe(
+    'In Turabian Shows a Sample Title Page for a Class Paper.'
+  );
+});
+
+it('transform edge case', () => {
+  expect(toChicago('camelCase PascalCase snake_case and kebab-case')).toBe(
+    'Camelcase Pascalcase Snake_case and Kebab-Case'
+  );
+});