Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# http://editorconfig.org

# A special property that should be specified at the very top of the file.
# When set to true, it stops Editorconfig from searching any higher
# in the directory tree for .editorconfig files.
root = true

[*]
# Indentation style
# Possible values - tab, space
indent_style = space

# Indentation size in single-spaced characters
# Possible values - an integer, tab
indent_size = 2

# Newline character(s) to use (varies by OS otherwise)
# Possible values - lf, crlf, cr
end_of_line = lf

# File character encoding
# Possible values - latin1, utf-8, utf-16be, utf-16le
charset = utf-8

# Denotes whether to trim whitespace at the end of lines
# Possible values - true, false
trim_trailing_whitespace = true

# quote_type = single

[*.md]
trim_trailing_whitespace = false

# Denotes whether file should end with a newline
# Possible values - true, false
insert_final_newline = true
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'env': {
'browser': true,
'commonjs': true,
'es2021': true,
},
'extends': ['eslint:recommended', 'plugin:jest/recommended'],
'overrides': [],
'parserOptions': {
'ecmaVersion': 'latest',
},
'rules': {},
};
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto

*.*js text eol=lf
*.ts text eol=lf
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Unit Tests

on:
push:
paths:
- 'lib/**/*.js'
- '__tests__/**/*.js'
- 'package.json'
- '.github/workflows/test.yml'
branches: [ master, develop ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
test:

runs-on: ubuntu-22.04

strategy:
matrix:
node-version: [v16.x, v18.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: mskelton/setup-yarn@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn install --immutable
- name: Run tests
run: yarn test
91 changes: 6 additions & 85 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,88 +1,9 @@
# Logs
logs
node_modules
.idea
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
dist/
types/
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
coverage.lcov
.DS_Store
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# brainfuckify
_A naive ascii text to brainfuck compiler_

A naive ascii text to brainfuck compiler.

## Why?

Typing stuff so that it prints normally in BF is a huge pain when done manually.

## Installation

```bash
npm install brainfuckify
```

## Usage

```javascript
const brainfuckify = require('brainfuckify');

Expand All @@ -32,4 +36,5 @@ brainfuckify('Hello, world!');
Also see test folder for an example.

## License?

MIT
15 changes: 15 additions & 0 deletions __tests__/test.brainfuckify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {
compileToJsWeb,
} = require('hirnfick');
const brainfuckify = require('../lib/brainfuckify');

describe('brainfuckify', () => {
it('Encodes text to correct brainfuck code', () => {
// A GLaDOS quote
const inputText = 'Thank you for helping us help you help us all.';
const generatedBrainfuck = brainfuckify(inputText);
const generatedJavaScript = compileToJsWeb(generatedBrainfuck);
const generatedFunction = new Function(`${generatedJavaScript} return main().output;`);
expect(generatedFunction().trim()).toBe(inputText);
});
});
15 changes: 15 additions & 0 deletions lib/brainfuckify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const repeat = require('./util/repeat');

/***
* Eagerly compiles a bit of text to brainfuck.
* @param {string} text A string of text.
* @returns {string} Generated brainfuck code.
*/
function brainfuckify(text) {
return [...text]
.map((char) => char.charCodeAt(0))
.map((asciiValue) => repeat('+', asciiValue))
.join('.>\n') + '.';
}

module.exports = brainfuckify;
5 changes: 5 additions & 0 deletions lib/util/repeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function repeat(str, times) {
return Array(times).fill(0).map(() => str).join('');
}

module.exports = repeat;
Loading