# hasShape

Takes an object of validators defining the possible *shape* of an object and returns a new function that reports whether the received objects matches that shape or not.

```javascript
import hasShape form 'deep-waters/hasShape';
import isString form 'deep-waters/isString';
import isNumber form 'deep-waters/isNumber';

const isUser = hasShape({
    name: isString,
    age: isNumber,
}); 

isUser({ name: 'Antonio Rù', age: 33 }); // → true
isUser({ foo: 'bar' }); // → false
isUser({ name: 'Antonio Rù', age: 33, meta: { privacy: true } }); // → true
```

{% hint style="warning" %}
The created validator **isUser** only makes sure the received object has all the defined keys and each key matches the defined validation. \
It does not check on properties not defined by the shape, meaning it will return true even if the object has additional properties.
{% endhint %}

{% hint style="success" %}
hasShape could be easily used to define nested objects:
{% endhint %}

```javascript
import hasShape form 'deep-waters/hasShape';
import isString form 'deep-waters/isString';
import isNumber form 'deep-waters/isNumber';
import isBoolean from 'deep-waters/isBoolean';

const isUser = hasShape({
    name: isString,
    age: isNumber,
    meta: hasShape({
        privacy: isBoolean,
    })
}); 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://antonioru.gitbook.io/deep-waters/validators/hasshape.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
