Skip to content

Commit

Permalink
feat(name): bump name to domain-glossary namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Dec 12, 2024
1 parent 34ec02e commit 16c8058
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 62 deletions.
16 changes: 10 additions & 6 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

<<<<<<< Updated upstream
## [1.2.0](https://github.com/ehmpathy/uni-phone/compare/v1.1.1...v1.2.0) (2024-12-04)


Expand All @@ -8,29 +9,32 @@
* **cast:** expose cast asPartialPhoneInHumanWords ([f1efe3d](https://github.com/ehmpathy/uni-phone/commit/f1efe3d79508aeaf9a14e643f928e5f67eae868c))

## [1.1.1](https://github.com/ehmpathy/uni-phone/compare/v1.1.0...v1.1.1) (2024-12-03)
=======
## [1.1.1](https://github.com/ehmpathy/domain-glossary-phone/compare/v1.1.0...v1.1.1) (2024-12-03)
>>>>>>> Stashed changes

### Bug Fixes

* **pkg:** ensure new cast is exposed on index ([0a1a5c2](https://github.com/ehmpathy/uni-phone/commit/0a1a5c23d72aecb996c3b85cbc48da8043b6f57f))
* **pkg:** ensure new cast is exposed on index ([0a1a5c2](https://github.com/ehmpathy/domain-glossary-phone/commit/0a1a5c23d72aecb996c3b85cbc48da8043b6f57f))

## [1.1.0](https://github.com/ehmpathy/uni-phone/compare/v1.0.1...v1.1.0) (2024-12-03)
## [1.1.0](https://github.com/ehmpathy/domain-glossary-phone/compare/v1.0.1...v1.1.0) (2024-12-03)


### Features

* **cast:** cast to phone in human words ([9f2eaea](https://github.com/ehmpathy/uni-phone/commit/9f2eaea0852bc51eee230387aeb5d6b045d3db69))
* **cast:** cast to phone in human words ([9f2eaea](https://github.com/ehmpathy/domain-glossary-phone/commit/9f2eaea0852bc51eee230387aeb5d6b045d3db69))

## [1.0.1](https://github.com/ehmpathy/uni-phone/compare/v1.0.0...v1.0.1) (2024-12-03)
## [1.0.1](https://github.com/ehmpathy/domain-glossary-phone/compare/v1.0.0...v1.0.1) (2024-12-03)


### Bug Fixes

* **check:** extend isUniPhoneNumber withAssure ([47f530b](https://github.com/ehmpathy/uni-phone/commit/47f530b76b2c56066895b8162cbcfb608dddf722))
* **check:** extend isPhoneNumber withAssure ([47f530b](https://github.com/ehmpathy/domain-glossary-phone/commit/47f530b76b2c56066895b8162cbcfb608dddf722))

## 1.0.0 (2024-11-29)


### Features

* **init:** initialize based on uni-time ([8db8ce5](https://github.com/ehmpathy/uni-phone/commit/8db8ce5ee3b925ebd43aadef4e8b8425d445c227))
* **init:** initialize based on uni-time ([8db8ce5](https://github.com/ehmpathy/domain-glossary-phone/commit/8db8ce5ee3b925ebd43aadef4e8b8425d445c227))
2 changes: 1 addition & 1 deletion declapract.use.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ declarations: npm:declapract-typescript-ehmpathy
useCase: npm-package # specify which use case your repo is following, see `declapract-typescript-ehmpathy:src/useCases.yml` for options
variables: # specify the values of the variables to use against checks
organizationName: 'ehmpathy'
projectName: 'uni-phone'
projectName: 'domain-glossary-phone'
10 changes: 10 additions & 0 deletions package-lock.json

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

18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{
"name": "uni-phone",
"name": "domain-glossary-phone",
"author": "ehmpathy",
"description": "a glossary of universally intuitive time, date, and duration domain literals",
"description": "A glossary of intuitive, universally unambiguous phone definitions and useful procedures.",
"version": "1.2.0",
"repository": "ehmpathy/uni-phone",
"homepage": "https://github.com/ehmpathy/uni-phone",
"repository": "ehmpathy/domain-glossary-phone",
"homepage": "https://github.com/ehmpathy/domain-glossary-phone",
"keywords": [
"time",
"date",
"datetime",
"UniDate",
"UniDateTime",
"UniDuration"
"phone",
"phone number"
],
"bugs": "https://github.com/ehmpathy/uni-phone/issues",
"bugs": "https://github.com/ehmpathy/domain-glossary-phone/issues",
"license": "MIT",
"main": "dist/index.js",
"engines": {
Expand Down
28 changes: 14 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# uni-phone
# domain-glossary-phone

![test](https://github.com/ehmpathy/uni-phone/workflows/test/badge.svg)
![publish](https://github.com/ehmpathy/uni-phone/workflows/publish/badge.svg)
![test](https://github.com/ehmpathy/domain-glossary-phone/workflows/test/badge.svg)
![publish](https://github.com/ehmpathy/domain-glossary-phone/workflows/publish/badge.svg)

A glossary of intuitive, universally unambiguous phone domain literals.
A glossary of intuitive, universally unambiguous phone definitions and useful procedures.

# purpose

declare a universally unambiguous serialization format for phones
- `UniPhoneNumber` = [E.164](https://en.wikipedia.org/wiki/E.164)
- `UniPhone` = `{ number: UniPhoneNumber }`
- `PhoneNumber` = [E.164](https://en.wikipedia.org/wiki/E.164)
- `Phone` = `{ number: PhoneNumber }`

usecases
- clarify the format a string should be in (`const phoneNumber: UniPhoneNumber = '+13231110101'`)
- cast date to universal format (`const phoneNumber: UniPhoneNumber = toUniPhoneNumber('(323) 111-0101')`)
- narrow type of strings with runtime validation (`if (!isUniPhoneNumber(input)) throw new Error('wrong format')`)
- clarify the format a string should be in (`const phoneNumber: PhoneNumber = '+13231110101'`)
- cast date to universal format (`const phoneNumber: PhoneNumber = toPhoneNumber('(323) 111-0101')`)
- narrow type of strings with runtime validation (`if (!isPhoneNumber(input)) throw new Error('wrong format')`)


# install

```sh
npm install uni-phone
npm install domain-glossary-phone
```

# use
Expand All @@ -30,21 +30,21 @@ npm install uni-phone
### declare that a phone or phone.number must be in the universal format

```ts
const phone: UniPhone;
const phoneNumber: UniPhoneNumber;
const phone: Phone;
const phoneNumber: PhoneNumber;
```


### assure that a phone number is in the universal phormat

```ts
const phone: UniPhone = { number: isUniPhoneNumber.assure('+13231110101') }
const phone: Phone = { number: isPhoneNumber.assure('+13231110101') }
```


### cast a phone number into the universal format

```ts
const phone: UniPhone = { number: asUniPhoneNumber('(323) 111-0101') }
const phone: Phone = { number: asPhoneNumber('(323) 111-0101') }
```

4 changes: 2 additions & 2 deletions src/UniPhone.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DomainLiteral } from 'domain-objects';

export interface UniPhone {
export interface Phone {
id?: number;
number: string;
}
export class UniPhone extends DomainLiteral<UniPhone> implements UniPhone {}
export class Phone extends DomainLiteral<Phone> implements Phone {}
2 changes: 1 addition & 1 deletion src/UniPhoneNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { AsOfGlossary } from 'domain-glossaries';
* a phone number in the universal E.164 format
* - E.164 example: +18175698900
*/
export type UniPhoneNumber = AsOfGlossary<string, 'uni-phone'>;
export type PhoneNumber = AsOfGlossary<string, 'domain-glossary-phone'>;
10 changes: 5 additions & 5 deletions src/asUniPhoneInHumanWords.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { asUniPhoneInHumanWords } from './asUniPhoneInHumanWords';
import { isUniPhoneNumber } from './isUniPhoneNumber';
import { asPhoneInHumanWords } from './asPhoneInHumanWords';
import { isPhoneNumber } from './isPhoneNumber';

describe('asUniPhoneInHumanWords', () => {
describe('asPhoneInHumanWords', () => {
it('should look right', () => {
const result = asUniPhoneInHumanWords({
number: isUniPhoneNumber.assure('+13175557777'),
const result = asPhoneInHumanWords({
number: isPhoneNumber.assure('+13175557777'),
});
expect(result).toEqual('(317) 555-7777');
});
Expand Down
6 changes: 3 additions & 3 deletions src/asUniPhoneInHumanWords.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { UniPhone } from './UniPhone';
import { Phone } from './Phone';

/**
* .what = casts a uni phone into human words
* .example
* - +13335557777 => (333) 555-7777
*/
export const asUniPhoneInHumanWords = (input: UniPhone): string => {
export const asPhoneInHumanWords = (input: Phone): string => {
// Validate input: must start with '+' followed by digits
const phoneRegex = /^\+(\d{1,3})(\d{3})(\d{3})(\d{4})$/;
const match = input.number.match(phoneRegex);

if (!match) {
throw new Error(
'Invalid UniPhone format. Expected format: +<country-code><10-digit-phone>',
'Invalid Phone format. Expected format: +<country-code><10-digit-phone>',
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/asUniPhoneNumber.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { asUniPhoneNumber } from './asUniPhoneNumber';
import { asPhoneNumber } from './asPhoneNumber';

describe('asUniPhoneNumber', () => {
describe('asPhoneNumber', () => {
it('should be able to normalize a phone number', () => {
const fromVariant1 = asUniPhoneNumber('317 821 1234');
const fromVariant2 = asUniPhoneNumber('(317) 821-1234');
const fromVariant3 = asUniPhoneNumber('317821-1234');
const fromVariant1 = asPhoneNumber('317 821 1234');
const fromVariant2 = asPhoneNumber('(317) 821-1234');
const fromVariant3 = asPhoneNumber('317821-1234');
expect(fromVariant1).toEqual('+13178211234');
expect(fromVariant2).toEqual(fromVariant1);
expect(fromVariant3).toEqual(fromVariant2);
Expand Down
8 changes: 4 additions & 4 deletions src/asUniPhoneNumber.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { UnexpectedCodePathError } from '@ehmpathy/error-fns';
import { phone } from 'phone';

import { UniPhoneNumber } from './UniPhoneNumber';
import { PhoneNumber } from './PhoneNumber';

/**
* casts a phone number into the universal format, E.164
*/
export const asUniPhoneNumber = (input: string): UniPhoneNumber => {
export const asPhoneNumber = (input: string): PhoneNumber => {
const { phoneNumber: normalizedPhoneNumber } = phone(input);
if (!normalizedPhoneNumber)
throw new UnexpectedCodePathError(
'input was not a valid phone number. can not be cast to uni-phone-number',
'input was not a valid phone number. can not be cast to domain-glossary-phone-number',
{ input },
);
return normalizedPhoneNumber as UniPhoneNumber;
return normalizedPhoneNumber as PhoneNumber;
};
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './UniPhoneNumber';
export * from './isUniPhoneNumber';
export * from './asUniPhoneNumber';
export * from './PhoneNumber';
export * from './isPhoneNumber';
export * from './UniPhone';
export * from './asUniPhoneInHumanWords';
export * from './asPhoneNumber';
export * from './isPhoneNumber';
export * from './Phone';
export * from './asPhoneInHumanWords';
export * from './asPartialPhoneInHumanWords';
10 changes: 5 additions & 5 deletions src/isUniPhoneNumber.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { withAssure } from 'type-fns';

import { UniPhoneNumber } from './UniPhoneNumber';
import { asUniPhoneNumber } from './asUniPhoneNumber';
import { PhoneNumber } from './PhoneNumber';
import { asPhoneNumber } from './asPhoneNumber';

/**
* checks whether a string is a universally formatted phone number
*/
export const isUniPhoneNumber = withAssure(
(input: string): input is UniPhoneNumber => {
export const isPhoneNumber = withAssure(
(input: string): input is PhoneNumber => {
try {
const universal = asUniPhoneNumber(input);
const universal = asPhoneNumber(input);
return input === universal;
} catch {
// if there was an error, then its not a phone number, so defo not a universal phone number
Expand Down

0 comments on commit 16c8058

Please sign in to comment.