Skip to content

Commit

Permalink
Merge pull request #4 from ideal-postcodes/ts
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
cblanc committed Jun 8, 2018
2 parents a1220e8 + 8cb2967 commit b36369c
Show file tree
Hide file tree
Showing 16 changed files with 5,255 additions and 94 deletions.
21 changes: 10 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,51 @@ version: 2
jobs:
node6:
docker:
- image: circleci/node:6

- image: circleci/node:6
steps:
- checkout
- restore_cache:
keys:
- npm-deps-{{ checksum "package.json" }}
- npm-deps-{{ checksum "package-lock.json" }}
- run: npm install
- save_cache:
key: npm-deps-{{ checksum "package.json" }}
key: npm-deps-{{ checksum "package-lock.json" }}
paths:
- node_modules/
- run: npm test

- run: npm run coverage

node8:
docker:
- image: circleci/node:8

steps:
- checkout
- restore_cache:
keys:
- npm-deps-{{ checksum "package.json" }}
- npm-deps-{{ checksum "package-lock.json" }}
- run: npm install
- save_cache:
key: npm-deps-{{ checksum "package.json" }}
key: npm-deps-{{ checksum "package-lock.json" }}
paths:
- node_modules/
- run: npm test
- run: npm run coverage

node10:
docker:
- image: circleci/node:10

steps:
- checkout
- restore_cache:
keys:
- npm-deps-{{ checksum "package.json" }}
- npm-deps-{{ checksum "package-lock.json" }}
- run: npm install
- save_cache:
key: npm-deps-{{ checksum "package.json" }}
key: npm-deps-{{ checksum "package-lock.json" }}
paths:
- node_modules/
- run: npm test
- run: npm run coverage

workflows:
version: 2
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ jspm_packages
.npm

# Optional REPL history
.node_repl_history
.node_repl_history

# Source maps used for nyc
dist/index.js.map
13 changes: 13 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.*
*.log
**/tsconfig.json
tsconfig.*.json
tslint.json

coverage
node_modules
lib
docs

## this is generated by `npm pack`
*.tgz
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

Any changes, including backwards incompatible changes will be listed here

## 2.0.0 (08/06/2018)
- *Breaking Change.* Module now exports an object with a capitalisation function

```js
// New import method

const { capitalisePostTown } = require("capitalise-post-town");
```

- *Breaking Change.* Location of compiled javascript moved to `dist/index.js`
- Typings file available
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
# Capitalise UK Post Towns ![Travis](https://travis-ci.org/ideal-postcodes/capitalise-post-town.svg?branch=master)
[![CircleCI](https://circleci.com/gh/ideal-postcodes/capitalise-post-town.svg?style=svg)](https://circleci.com/gh/ideal-postcodes/capitalise-post-town) [![Coverage Status](https://coveralls.io/repos/github/ideal-postcodes/capitalise-post-town/badge.svg?branch=master)](https://coveralls.io/github/ideal-postcodes/capitalise-post-town?branch=master)

# Capitalise UK Post Towns

Small javascript library and test suite that will properly capitalise post town names

Takes into account odd peculiar naming rules and exceptions

Input needs to be correctly spaced and/or hyphenated

##
## Install

```
npm install capitalise-post-town
```

## Usage

```javascript
const cap = require("capitalise-post-town");
const { capitalisePostTown } = require("capitalise-post-town");

// Simple Case
cap("DRYBROOK") // => Drybrook
capitalisePostTown("DRYBROOK") // => Drybrook

// Hypenated
cap("HENLEY-IN-ARDEN") // => Henley-in-Arden
capitalisePostTown("HENLEY-IN-ARDEN") // => Henley-in-Arden

// Minor uncapitalised words
cap("WALTON on THE naze") // => Walton on the Naze
capitalisePostTown("WALTON on THE naze") // => Walton on the Naze

// Exception
cap("BO'NESS") // => Bo'Ness
capitalisePostTown("BO'NESS") // => Bo'Ness
```

## License
Expand Down
1 change: 0 additions & 1 deletion dist/capitalise-post-town.min.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const capitalisePostTown: (postTown: string) => string;
44 changes: 44 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions gulpfile.js

This file was deleted.

30 changes: 17 additions & 13 deletions index.js → lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,45 @@ const exclusion = /^(of|le|upon|on|the)$/;
const containsAmpersand = /\w+&\w+/;

// capitalise word with exceptions on exclusion list
const capitalise = word => {
const capitaliseWord = (word: string): string => {
word = word.toLowerCase();
if (word.match(exclusion)) return word;
if (word.match(containsAmpersand)) return word.toUpperCase();

return word.charAt(0).toUpperCase() + word.slice(1);
};

const joiner = /-/;
const joinerWord = /^(in|de|under|upon|y|on|over|the|by)$/;

// Check for names connected with hyphens
const checkJoins = string => {
const checkJoins = (string: string): string => {
if (string.match(joiner) === null) return string;

return string
.split("-")
.map(string => {
if (string.match(joinerWord)) return string.toLowerCase();
return capitalise(string);
.map(str => {
if (str.match(joinerWord)) return str.toLowerCase();

return capitaliseWord(str);
})
.join("-")
}

const boness = /bo'ness/i;

// Single instance cases
const exceptions = string => {
if (string.match(boness)) return "Bo'Ness";
return string;
// Handles unusual names which cannot be easily generalised into a rule
const exceptions = (str: string): string => {
if (str.match(boness)) return "Bo'Ness";

return str;
}

module.exports = posttown => {
return posttown
export const capitalisePostTown = (postTown: string): string => {
return postTown
.split(" ")
.map(capitalise)
.map(capitaliseWord)
.map(checkJoins)
.map(exceptions)
.join(" ");
};
}
6 changes: 6 additions & 0 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--require ts-node/register
--require source-map-support/register
--recursive
--full-trace
--bail
test/*.ts

0 comments on commit b36369c

Please sign in to comment.