Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
juanluispaz committed Aug 14, 2019
0 parents commit c92537a
Show file tree
Hide file tree
Showing 7 changed files with 579 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Tt]humbs.db
.DS_Store
node_modules
npm-debug.log*
coverage
package-lock.json
dist
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Tt]humbs.db
.DS_Store
node_modules
npm-debug.log*
coverage
package-lock.json
test
.travis.yml
src
tsconfig.json
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Juan Luis Paz Rojas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# ts-extended-types

[![npm](https://img.shields.io/npm/v/ts-extended-types.svg)](http://npm.im/ts-extended-types)
[![minified size](https://badgen.net/bundlephobia/min/ts-extended-types)](https://bundlephobia.com/result?p=ts-extended-types)
[![minified & gziped size](https://badgen.net/bundlephobia/minzip/ts-extended-types)](https://bundlephobia.com/result?p=ts-extended-types)

Set of complementary basic types related to the ones provided by TypeScript to make your application even more type-safe

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save ts-extended-types
```

## Basic usage

```ts
import {int, stringInt, double, stringDouble, LocalDate, LocalTime, LocalDateTime } from 'ts-extended-types';

var intNumber: int;
var veryBigInt: stringInt
var doubleNumber: double;
var veryBigDoubleNumber: stringDouble
var localDate: LocalDate;
var localTime: LocalTime;
var localDateTime: LocalDateTime;
```

## Type definitions

- **`int`**: type that represents a integer number. It can be assigned to a number, but it cannot be assigned from a number.
- **`stringInt`**: type that represents a integer number. It can be assigned to a number, but it cannot be assigned from a number: it can be so long that can be represented using a string instead of a number.
- **`double`**: type that represents a floating point number with double precision. It can be assigned to a number, but it cannot be assigned from a number.
- **`stringDouble`**: type that represents a floating point number with double precision; it can be so long that can be represented using a string instead of a number.
- **`LocalDate`**: type that represents a local date without time (without timezone). **Provided methods**:
- **`getFullYear(): int`**: Gets the year
- **`getMonth(): int`**: Gets the month (value between 0 to 11)
- **`getDate(): int`**: Gets the day-of-the-month
- **`getDay(): int`**: Gets the day of the week (0 represents Sunday)
- **`LocalTime`**: type that represents a local time without date (without timezone). **Provided methods**:
- **`getHours(): int`**: Gets the hours
- **`getMinutes(): int`**: Gets the minutes
- **`getSeconds(): int`**: Gets the seconds
- **`getMilliseconds(): int`**: Gets the milliseconds
- **`LocalDateTime`**: type that represents a local date with time (without timezone). **Provided methods**: all methods provided by `LocalDate` and `LocalTime` plus:
- **`getTime(): int`**: Gets the time value in milliseconds

**Note**:
- In JavaScript `int`or `double` don't exists, all of these values as represented using a `number`.
- In JavaScript `stringInt`or `stringDouble` don't exists, all of these values as represented using a `number` or a `string`.
- In JavaScript `LocalDate`, `LocalTime` or `LocalDateTime` don't exists, all of these values are represented using the `Date` object.

## Provided functions

### Provided int functions

- **`isInt(value: any) => value is int`**: Returns `true` if the value is a `int` number, otherwise returns `false`.
- **`asInt(value: number) => int`**: Cast the number provided by argument as `int`, throws an error if the provided number is not an integer.
- **`roundToInt(value: number) => int`**: Round the provided number to an integer and then cast it to `int`.
- **`truncateToInt(value: number) => int`**: Truncate the provided number to an integer and then cast it to `int`.
- **`floorToInt(value: number): int`**: Floor the provided number to an integer and then cast it to `int`.
- **`ceilToInt(value: number): int`**: Ceil the provided number to an integer and then cast it to `int`.

### Provided stringInt functions

- **`isStringInt(value: any) => value is stringInt`**: Returns `true` if the value is a `stringInt` number, otherwise returns `false`.
- **`asStringInt(value: number|string) => stringInt`**: Cast the number provided by argument as `stringInt`, throws an error if the provided number is not an integer.
- **`roundToStringInt(value: number) => stringInt`**: Round the provided number to an integer and then cast it to `stringInt`.
- **`truncateToStringInt(value: number) => stringInt`**: Truncate the provided number to an integer and then cast it to `stringInt`.
- **`floorToStringInt(value: number): stringInt`**: Floor the provided number to an integer and then cast it to `stringInt`.
- **`ceilToStringInt(value: number): stringInt`**: Ceil the provided number to an integer and then cast it to `stringInt`.

### Provided double functions

- **`isDouble(value: any) => value is double`**: Returns `true` if the value is a `double` precision number, otherwise returns `false`.
- **`asDouble(value: number) => double`**: Cast the number provided by argument as `double`.

### Provided stringDouble functions

- **`isStringDouble(value: any) => value is stringDouble`**: Returns `true` if the value is a `stringDouble` precision number, otherwise returns `false`.
- **`asStringDouble(value: number|string) => double`**: Cast the number provided by argument as `stringDouble`, throws an error if the provided number is not a double.

### Provided LocalDate functions

- **`createLocalDate() => LocalDate`**: create a new `LocalDate` with the current date.
- **`createLocalDate(date: Date) => LocalDate`**: create a new `LocalDate` with the same date provided by argument.
- **`createLocalDate(year: number, month: number, date: number): LocalDate`**: create a new `LocalDate` with the year, month and date (day of the month) provided by arguments.
- **`isLocalDate(value: any): value is LocalDate`**: Returns `true` if the value is a `LocalDate`, otherwise returns `false`

### Provided LocalTime functions

- **`createLocalTime() => LocalTime`**: create a new `LocalTime` with the current time.
- **`createLocalTime(date: Date) => LocalTime`**: create a new `LocalTime` with the same time provided by argument.
- **`createLocalTime(hours: number, minutes?: number, seconds?: number, milliseconds?: number): LocalTime`**: create a new `LocalTime` with the hours, minutes, seconds and milliseconds provided by arguments.
- **`isLocalTime(value: any): value is LocalTime`**: Returns `true` if the value is a `LocalTime`, otherwise returns `false`

### Provided LocalDateTime functions

- **`createLocalDateTime() => LocalDateTime`**: create a new `LocalDate` with the current date and time.
- **`createLocalDateTime(date: Date) => LocalDateTime`**: create a new `LocalDateTime` with the same date and time provided by argument.
- **`createLocalDateTime(year: number, month: number, date: number, hours?: number, minutes?: number, seconds?: number, milliseconds?: number): LocalDateTime`**: create a new `LocalDateTime` with the year, month, date (day of the month), hours, minutes, seconds and milliseconds provided by arguments.
- **`isLocalDate(value: any): value is LocalDate`**: Returns `true` if the value is a `LocalDate`, otherwise returns `false`

## License

MIT

<!--
Edited with: https://stackedit.io/app
-->
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "ts-extended-types",
"version": "0.10.0",
"description": "Set of complementary basic types related to the ones provided by TypeScript to make your application even more type-safe",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {},
"devDependencies": {
"typescript": "^3.5.3"
},
"scripts": {
"build": "rm -Rf dist/*; tsc",
"prepublish": "npm run build"
},
"repository": {
"type": "git",
"url": "https://github.com/juanluispaz/ts-extended-types.git"
},
"keywords": [
"typescript",
"type",
"types",
"int",
"double",
"date",
"local date",
"time",
"local time",
"datetime",
"date time",
"local datetime",
"local date time"
],
"author": {
"name": "Juan Luis Paz Rojas",
"url": "http://github.com/juanluispaz"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/juanluispaz/ts-extended-types/issues"
},
"homepage": "https://github.com/juanluispaz/ts-extended-types"
}

0 comments on commit c92537a

Please sign in to comment.