Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Update package name to ts-optchain (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neville Bowers authored Aug 10, 2018
1 parent e276562 commit 18e860f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Optional Chaining for TypeScript

The `ts-oc` library is an implementation of optional chaining with default value support for TypeScript. `ts-oc` helps the developer produce less verbose code while preserving TypeScript typings when traversing deep property structures. This library serves as an interim solution pending JavaScript/TypeScript built-in support for optional chaining in future releases (see: [Related Resources](#related)).
The `ts-optchain` library is an implementation of optional chaining with default value support for TypeScript. `ts-optchain` helps the developer produce less verbose code while preserving TypeScript typings when traversing deep property structures. This library serves as an interim solution pending JavaScript/TypeScript built-in support for optional chaining in future releases (see: [Related Resources](#related)).

## Install

```bash
npm i --save ts-oc
npm i --save ts-optchain
```

### Requirements
Expand All @@ -16,7 +16,7 @@ npm i --save ts-oc
## Example Usage

```typescript
import { oc } from 'ts-oc';
import { oc } from 'ts-optchain';

interface I {
a?: string;
Expand All @@ -43,9 +43,9 @@ const x: I = {
};


// Here are a few examples of deep object traversal using (a) optional chaining vs
// Here are a few examples of deep object traversal using (a) optional chaining vs
// (b) logic expressions. Each of the following pairs are equivalent in
// result. Note how the benefits of optional chaining accrue with
// result. Note how the benefits of optional chaining accrue with
// the depth and complexity of the traversal.

oc(x).a(); // 'hello'
Expand Down Expand Up @@ -123,21 +123,21 @@ However, when using tools like `lodash` the developer loses the benefits of:

## Solution

Using the `ts-oc` utility, `getHomeStreet` can be concisely written as:
Using the `ts-optchain` utility, `getHomeStreet` can be concisely written as:

```typescript
import { oc } from 'ts-oc';
import { oc } from 'ts-optchain';

function getHomeStreet(user: IUser, defaultValue?: string) {
return oc(user).home.address.street(defaultValue);
}
```

Other features of `ts-oc` include:
Other features of `ts-optchain` include:

### Type Preservation

`ts-oc` preserves TypeScript typings through deep tree traversal. For example:
`ts-optchain` preserves TypeScript typings through deep tree traversal. For example:

```typescript
// phoneNumberOptional is of type: string | undefined
Expand All @@ -149,7 +149,7 @@ const phoneNumberRequired = oc(user).home.phoneNumber('+1.555.123.4567');

### Array Types

`ts-oc` supports traversal of Array types by index. For example:
`ts-optchain` supports traversal of Array types by index. For example:

```typescript
interface IItem {
Expand All @@ -168,7 +168,7 @@ function getFirstItemName(collection: ICollection) {

### Function Types

`ts-oc` supports traversal to function values. For example:
`ts-optchain` supports traversal to function values. For example:

```typescript
interface IThing {
Expand All @@ -181,12 +181,12 @@ const result = oc(thing).getter(() => 'Default Getter')();

### Code-Completion

`ts-oc` enables code-completion assistance in popular IDEs such as Visual Studio Code when writing tree-traversal code.
`ts-optchain` enables code-completion assistance in popular IDEs such as Visual Studio Code when writing tree-traversal code.

## <a name="related"></a>Related Resources

* [Optional Chaining for JavaScript (TC39 Proposal)](https://github.com/tc39/proposal-optional-chaining)

## License

`ts-oc` is MIT Licensed.
`ts-optchain` is MIT Licensed.
4 changes: 2 additions & 2 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "ts-oc",
"name": "ts-optchain",
"version": "0.1.0",
"description": "Optional Chaining for TypeScript",
"repository": {
"type": "git",
"url": "git+https://github.com/rimeto/ts-oc.git"
"url": "git+https://github.com/rimeto/ts-optchain.git"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"prepublish": "npm run build",
"prepublishOnly": "npm run build",
"test": "jest"
},
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { oc } from '../index';

describe('ts-oc', () => {
describe('ts-optchain', () => {
it('sanity checks', () => {
interface X {
a: string;
Expand Down

0 comments on commit 18e860f

Please sign in to comment.