Skip to content

Commit 38738d3

Browse files
committed
Updated README and a few typings.
1 parent 5bbffc4 commit 38738d3

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,62 @@
22
> A class that maps between a variety of data types.
33
44
## Installation
5-
Simply do: `npm install marshaller`.
5+
Simply do: `npm install @wessberg/marshaller`.
66

77
## Usage
8-
```typescript
8+
```javascript
99
const marshaller = new Marshaller();
1010

1111
marshaller.marshal("true", Boolean); // true
1212
marshaller.marshal("0", Boolean); // false
1313
marshaller.marshal([1, 2, false, true], String); // [ 1, 2, false, true]
1414
marshaller.marshal("Infinity"); // Auto-mapped to number - Infinity.
15+
marshaller.marshal<number, string>(123, "a hint") // "123", generic typecasting.
1516
```
1617

1718
As you can see, you simply pass some arbitrary data and *optionally* the type
1819
you want to map to. If you don't provide any, `Marshaller` will attempt to find
1920
the most appropriate type to map to using heuristics. The second argument, the hint,
2021
accepts either a constructor for a type or a concrete instance of one.
2122

23+
## API
24+
`marshal<T, U> (data: T, hint?: U|Newable<U>): U | null|undefined`
25+
26+
#### Params
27+
##### `data: T`
28+
The input data.
29+
30+
##### `hint?: U|Newable<U>`
31+
An optional hint to define which data type to marshal to. If omitted, the data will be parsed
32+
into the type `Marshaller` finds most appropriate.
33+
34+
#### Returns
35+
##### `U`
36+
The marshalled version of the input data.
37+
38+
## Roadmap
39+
* [X] Casting from/to `Set`.
40+
* [X] Casting from/to `Object`.
41+
* [X] Casting from/to `String`.
42+
* [X] Casting from/to `Number`.
43+
* [X] Casting from/to `Boolean`.
44+
* [X] Casting from/to `Array`.
45+
* [ ] Casting from/to `Date`.
46+
* [ ] Casting from/to `Function`
47+
* [ ] Casting from/to `Map`
48+
* [ ] Casting from/to `WeakSet`
49+
* [ ] Casting from/to `WeakMap`
50+
* [ ] Casting from/to `RegExp`
51+
2252
## Changelog:
2353

24-
**v1.0**:
54+
**v1.0.2**:
55+
56+
- Updated README and a few typings.
57+
58+
**v1.0.0**:
2559

2660
- First release.
2761

28-
[npm-url]: https://npmjs.org/package/marshaller
29-
[npm-image]: https://badge.fury.io/js/marshaller.svg
62+
[npm-url]: https://npmjs.org/package/@wessberg/marshaller
63+
[npm-image]: https://badge.fury.io/js/@wessberg/marshaller.svg

src/Marshaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Marshaller implements IMarshaller {
1717
* @param {U} [hint]
1818
* @returns {null|U}
1919
*/
20-
public marshal<T, U> (data: T, hint?: U): U | null|undefined {
20+
public marshal<T, U> (data: T, hint?: U|Newable<U>): U | null|undefined {
2121
if (hint != null) return <U | null>this.marshalTo(data, hint);
2222
else return <U | null>this.marshalToBestGuess<T>(data);
2323
}

0 commit comments

Comments
 (0)