Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Conversion #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
*.class
target/
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const df = new DecimalFormat('#.000');
const result = df.format(1.234);
```

```ts
import {DecimalFormat} from "@deloitte-digital-au/decimalformat";
const locale = { decimalSeparator: '.', groupingSeparator: ',' }
const df = new DecimalFormat('#.000');
const result = df.format(1.234, locale);
```

#### Using the parser

If you only require the internals of a pattern, you can parse an expression with the `DecimalFormat` class, with:
Expand All @@ -31,6 +38,12 @@ const { parser } = require('DecimalFormat');
const result = parser.parse('#.000');
```

```ts
import { parser, GrammarParsed } from "@deloitte-digital-au/decimalformat";
const result : GrammarParsed = parser.parse('#.000');
```


#### Grammar

The grammar is contained in `src/decimalformat.pegjs`
Expand Down Expand Up @@ -192,6 +205,20 @@ Tests can be run with:
npm run test
```

## Build & NPM package
Since the typescript implementation, we have got a build step which provides the package into the "target" folder. Currently, a source map and the typescript types files are generated as well.

```bash
npm run build
(cd target && npm publish)
```

If you want to use your local package version without publishing, you will need to link the target folder instead of the source.

```bash
(cd target && sudo npm link)
```

## License

**BSD 3-Clause License**
Expand Down
20 changes: 20 additions & 0 deletions dist/parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
declare module "@deloitte-digital-au/decimalformat/dist/parser" {
export function parse(input: string): GrammarParsed;

export interface GrammarParsed {
positive : Pattern,
negative : Pattern,
}

export interface Pattern {
prefix : string,
suffix : string,
decimalSeparatorAlwaysShown : boolean,
mantissa : boolean,
groupingSize : number,
minimumFractionDigits : number,
maximumFractionDigits : number,
minimumIntegerDigits : number,
maximumIntegerDigits : number,
}
}
Loading