Skip to content

Commit

Permalink
cube 2: hypercube sucked
Browse files Browse the repository at this point in the history
  • Loading branch information
julijane committed Nov 28, 2018
1 parent 16c577f commit 235572c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# letter-spacing

[![npm version](https://img.shields.io/badge/npm-1.0.7-brightgreen.svg)](https://www.npmjs.org/package/letter-spacing)
[![npm version](https://img.shields.io/badge/npm-1.0.8-brightgreen.svg)](https://www.npmjs.org/package/letter-spacing)
![build status](https://img.shields.io/badge/build-passing-brightgreen.svg)
![code coverage](https://img.shields.io/badge/coverage-9001%25-brightgreen.svg)
![install size](https://img.shields.io/badge/install_size-0.01TiB-brightgreen.svg)
Expand Down Expand Up @@ -120,6 +120,42 @@ i c
c i t a r d a u q y l l a t n e d i c c a
```

#### spacedCube(str)

Print the text as a cube.

```js
spacedCube('WILL IT BLEND')
```

```
W I L L I T B L E N D
I N N
L E E
L L L
B B
I
T T T
I I
B
L L L
E L L
N I I
D N E L B T I L L I W W
N I I
E L L
L L L
B
I I
T T T
I
B B
L L L
L E E
I N N
W I L L I T B L E N D
```

##### decaps(str, [spacing=1])

Reverses the string before spacing.
Expand All @@ -140,6 +176,7 @@ in promised versions:
##### spacedPromise(str, [spacing=1])
##### spacedUpPromise(str, [spacing=1])
##### spacedCakePromise(str)
##### spacedCubePromise(str)
##### decapsPromise(str, [spacing=1])

Example:
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ let decapsPromise = (str, spacing=1) => new Promise(resolve => resolve(decaps(st
let spacedCake = str=>str.split('').map((v,i)=>spaced(str[i]+(i==0?str.substr(1,str.length-2):i==str.length-1?decaps(str,0).substr(1,str.length-2):' '.repeat(str.length-2))+decaps(str,0)[i]+'\n')).join('')
let spacedCakePromise = str => new Promise(resolve => resolve(spacedCake(str)))

let spacedCube = str => [...str.split('').map((v,i)=>!i?str:i<str.length-1?str[i]+' '.repeat(str.length-2)+decaps(str,0)[i]+' '.repeat(i-1)+decaps(str,0)[i]:decaps(str,0)+' '.repeat(i-1)+decaps(str,0)[i]),...(str.split('').map((v,i)=>!i?'':i<str.length-1?' '.repeat(i)+decaps(str,0)[i]+' '.repeat(str.length-2)+str[i]+' '.repeat(str.length-i-2)+str[i]:' '.repeat(i)+str)).slice(1)].map(s=>spaced(s)).join('\n')
let spacedCubePromise = str => new Promise(resolve => resolve(spacedCube(str)))

module.exports = {
spaced,
spacedUp,
spacedCake,
spacedCube,
decaps,
spacedPromise,
spacedUpPromise,
spacedCakePromise,
spacedCubePromise,
decapsPromise
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "letter-spacing",
"version": "1.0.7",
"version": "1.0.8",
"description": "Add letter spacing to strings, for the browser and node.js. Optionally with Promises.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 235572c

Please sign in to comment.