Skip to content

Commit

Permalink
README.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorris committed Sep 5, 2024
1 parent a8215c6 commit 8232915
Showing 1 changed file with 78 additions and 2 deletions.
80 changes: 78 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Map one or more properties to a Record.
```javascript
import { Schema as s } from 'libtuple';
const companySchema = s.sDict({
const companySchema = s.sRecord({
name: s.string(),
phone: s.string(),
address: s.string(),
Expand All @@ -400,16 +400,48 @@ const company = companySchema({
phone: '+1-000-555-1234',
address: '123 Fake St, Anytown, USA',
});
console.log({company});
```

#### Schema.dict(properties)

Map one or more values to a Dict.

```javascript
import { Schema as s } from 'libtuple';
const companySchema = s.sDict({
name: s.string(),
phone: s.string(),
address: s.string(),
});
const company = companySchema({
name: 'Acme Corporation',
phone: '+1-000-555-1234',
address: '123 Fake St, Anytown, USA',
});
console.log({company});
```

#### Schema.nTuple(...values)

Map n values to a Tuple. Will append each value in the input to the Tuple using the same mapper.

```javascript
import { Schema as s } from 'libtuple';
const vectorSchema = s.nTuple(s.number());
const vec2 = vectorSchema([5, 10]);
const vec3 = vectorSchema([5, 10, 11]);
const vec4 = vectorSchema([5, 10, 11, 17]);
console.log({vec2, vec3, vec4});
```

#### Schema.nGroup(...values)

Map n values to a Group. Will append each value in the input to the Group using the same mapper.
Expand All @@ -421,7 +453,7 @@ Map n properties to a Record. Will append additional properties without mapping
```javascript
import { Schema as s } from 'libtuple';
const companySchema = s.sDict({
const companySchema = s.nRecord({
name: s.string(),
phone: s.string(),
address: s.string(),
Expand All @@ -432,6 +464,7 @@ const company = companySchema({
phone: '+1-000-555-1234',
address: '123 Fake St, Anytown, USA',
openHours: "9AM-7PM",
slogan: "We do business.",
});
```

Expand Down Expand Up @@ -460,6 +493,31 @@ Strictly map values to a Group. Will throw an error if the number of values does

Strictly map values to a Record. Will throw an error if the number of values does not match.

```javascript
import { Schema as s } from 'libtuple';
const companySchema = s.nRecord({
name: s.string(),
phone: s.string(),
address: s.string(),
});
const company = companySchema({
name: 'Acme Corporation',
phone: '+1-000-555-1234',
address: '123 Fake St, Anytown, USA',
});
// ERROR!
companySchema({
name: 'Acme Corporation',
phone: '+1-000-555-1234',
address: '123 Fake St, Anytown, USA',
openHours: "9AM-7PM",
slogan: "We do business.",
});
```

#### Schema.sDict(properties)

Strictly map values to a Dict. Will throw an error if the number of values does not match.
Expand Down Expand Up @@ -488,6 +546,24 @@ Exclusively map values to a Group. Will drop any keys not present in the schema.

#### Schema.xRecord(properties)

```javascript
const companySchema = s.xRecord({
name: s.string(),
phone: s.string(),
address: s.string(),
});
const company = companySchema({
name: 'Acme Corporation',
phone: '+1-000-555-1234',
address: '123 Fake St, Anytown, USA',
openHours: "9AM-7PM",
slogan: "We do business.",
});
console.log({company});
```

Exclusively map values to a Record. Will drop any keys not present in the schema.

#### Schema.xDict(properties)
Expand Down

0 comments on commit 8232915

Please sign in to comment.