# create-runkit-content-from-function

> exposes a function which transforms js function to runkit string source

Latest version **0.1.0** (published 2019-10-07) · 0 weekly downloads

## Install

```sh
npm install create-runkit-content-from-function
pnpm add create-runkit-content-from-function
yarn add create-runkit-content-from-function
bun add create-runkit-content-from-function
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-10-07 |
| First published | 2019-10-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Maximilien Garenne |
| Maintainers | hyphaene |
| Keywords | rollup, react, react component, rollup react, component |

## Links

- npm: https://www.npmjs.com/package/create-runkit-content-from-function
- Homepage: https://github.com/hyphaene-npm/create-runkit-content-from-function#readme
- Issues: https://github.com/hyphaene-npm/create-runkit-content-from-function/issues
- npm.io page: https://npm.io/package/create-runkit-content-from-function

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2019-10-07
- 0.0.1 — 2019-10-07
- 0.0.0 — 2019-10-07

## README

# create-runkit-content-from-function

## Purpose

This package ( no dependencies ! ) exposes a simple function to transform a js function into a string that React-runkit can consume as source ( via source props)

## Use
```javascript
import createRunkitContentFromJSFunction from 'create-runkit-content-from-function';
```

:warning: You'll need to redefine require for the function that will use require ( so it's valid js ) :warning:

such as :
```javascript
const require = () => {};
```

:warning: functions must be not in one line so it can work :warning:

bad :
```javascript
const test = () => 42;
```
good :
```javascript
const test = () => {
	return 42;
};
```


general use case :
```javascript
const myFunction = () => {
	// demonstration of filter
	const collection = [1,2];
	const filtered = collection.filter(x => x > 2);
	console.log(filtered);
}
```

will populate runkit with
```javascript
// demonstration of filter
const collection = [1,2];
const filtered = collection.filter(x => x > 2);
console.log(filtered);
```

This use case should not come so often since we usually don not want our runkit to be populated with an unique instruction such as
```javascript
return 42
 ```



### In situation example :
```javascript
import Embed from 'react-runkit'
import createRunkitContentFromJSFunction from 'create-runkit-content-from-function';

// only to allow to require some package in the runkit
const require = () => {}

const codeToInsertInEmbedRunkit = () => {
	const fetch = require('fetch');
	fetch('someUrl').then(()=> console.log('fetched ! '))
}

const ComponentDisplayed = () => <Embed source={createRunkitContentFromJSFunction(codeToInsertInEmbedRunkit)}/>

```

( but I wanted to let you know )

Please open an issue if needed.

Happy coding !

---
_Source: https://npm.io/package/create-runkit-content-from-function · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
