Creating Modules

Run the following to create a NodeJS module:

$bit
Copiedcopy
See command synopsis

Write the code

You component implementation usually lies in a file in the name of the component, and can grow to further files and directories as needed.

/**
 * determines whether `value` is of type string.
 */
export function isString(value: string) {
  return typeof str === 'string';
}
CopiedCopy

It is worthwhile to add JSDoc comments on your code. Use bit start to preview your component API reference and head to the component's API reference tab.

Exposing the API

Expose your component's API and public types in the component's main file (index.ts, by default):

export { isString } from './is-string.js';
CopiedCopy

Testing modules

Head over to your component's .spec.tsx file to add automated testing.

import { isString } from './is-string.js';

it('should return true as `foo` is a string', () => {
  expect(isString('foo')).toBe(true);
});
CopiedCopy

Avoid mocking component dependencies to allow for better intergration testing using Ripple CI. Learn more on Testing components.

Documentation

To modify your documentation, change the is-string.docs.mdx file inside the component directory. It uses the MDX format allowing for rich and interactive component documentation.

---
description: Determines whether `value` is of type string
---

A NodeJS module for determining whether `value` is of type string

### Component usage

```ts
isString('foo'); // echo `true`
isString(42); // echo `false`
```

Try it out!

```js live
isString('foo');
```
CopiedCopy

Use the playground to allow people to play with your components live from your component documentation.