Comparing version 0.0.0 to 0.0.1
{ | ||
"name": "magicpen", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Styled output in both consoles and browsers", | ||
"main": "MagicPen.js", | ||
"main": "magicpen.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sunesimonsen/magicpen.git" | ||
}, | ||
"scripts": { | ||
"test": "gulp test" | ||
}, | ||
"author": "Sune Simonsen", | ||
"dependencies": { | ||
"devDependencies": { | ||
"gulp": "^3.8.6", | ||
"gulp-istanbul": "^0.2.1", | ||
"gulp-mocha": "^0.5.1", | ||
"mocha": "^1.20.1", | ||
"unexpected": "^3.2.2" | ||
"sinon": "=1.9.1", | ||
"unexpected": "^3.2.2", | ||
"unexpected-sinon": "^3.0.2" | ||
} | ||
} |
336
README.md
@@ -1,1 +0,335 @@ | ||
![Under Construction](http://ocaml.org/img/under_construction_icon.gif) | ||
# MagicPen | ||
![This sucker is spraying rainbows and unicorns right and left](images/magic-pen-6-colours.jpg "This sucker is spraying rainbows and unicorns right and left") | ||
Create composable extensible styled text in both consoles and | ||
browsers. | ||
## Installation | ||
### Node | ||
Install it with NPM or add it to your `package.json`: | ||
``` | ||
$ npm install magicpen | ||
``` | ||
Then: | ||
```js | ||
var magicpen = require('magicpen'); | ||
var pen = magicpen('ansi'); | ||
pen.red('Hello').sp().green('world!'); | ||
console.log(pen.toString()); | ||
``` | ||
### Browser | ||
Include `magicpen.js`. | ||
```html | ||
<script src="magicpen.js"></script> | ||
``` | ||
this will expose the `magicpen` function under the following namespace: | ||
```js | ||
var magicpen = weknowhow.magicpen; | ||
var pen = magicpen('html'); | ||
pen.red('Hello').sp().green('world!'); | ||
document.getElementById('output').innerHTML = pen.toString(); | ||
``` | ||
### RequireJS | ||
Include the library with RequireJS the following way: | ||
```js | ||
require.config({ | ||
paths: { | ||
magicpen: 'path/to/magicpen' | ||
} | ||
}); | ||
define(['magicpen'], function (magicpen) { | ||
var pen = magicpen('html'); | ||
pen.red('Hello').sp().green('world!'); | ||
document.getElementById('output').innerHTML = pen.toString(); | ||
}); | ||
``` | ||
## Usage | ||
You create a new `magicpen` instance by calling the `magicpen` | ||
function. The function takes one parameter, the output mode. By | ||
default the `plain` mode is console output without colors. You can | ||
also choose the `ansi` mode or the `html` mode. The `ansi` mode will | ||
format the output for the console with colors and basic styling. The | ||
`html` mode will format the output in html with colors and basic | ||
styling. | ||
Let's try to create our first `magicpen` in `ansi` mode: | ||
```js | ||
var pen = magicpen('ansi'); | ||
pen.red('Hello').sp().green('world!'); | ||
console.log(pen.toString()); | ||
``` | ||
The above snippet create a new `magicpen` in `ansi` mode and writes | ||
_Hello_ in red, space and _world!_ in green and prints the formatted | ||
output to the console. This will produce the following output: | ||
![Hello world!](images/Hello world - ansi.png) | ||
Let's try to create the same output but format it as html: | ||
```js | ||
var pen = magicpen('html'); | ||
pen.red('Hello').sp().green('world!'); | ||
document.getElementById('output').innerHTML = pen.toString(); | ||
``` | ||
You will get the following output it the browser: | ||
![Hello world!](images/Hello world - html.png) | ||
## API | ||
### text(content, styleString...) | ||
Append the given content to the output with the styles specified in the style strings. | ||
#### Supported styles are: | ||
*Text properties*: `bold`, `dim`, `italic`, `underline`, `inverse`, `hidden`, `strikeThrough`. | ||
*Foreground colors*: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`. | ||
*Background colors*: `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`. | ||
#### Example: | ||
```js | ||
var pen = magicpen('ansi'); | ||
pen.text('Hello', 'red') | ||
.text(' ') | ||
.text('colorful', 'yellow, bold') | ||
.text(' ') | ||
.text('world', 'green', 'underline') | ||
.text('!', 'bgYellow, blue'); | ||
console.log(pen.toString()); | ||
``` | ||
![Hello colorful world](images/Hello colorful world.png) | ||
Notice that special characters might get escaped by this method. The | ||
example below shows how special html characters is escaped by the html | ||
mode. | ||
```js | ||
var pen = magicpen('html'); | ||
pen.text('<strong>Hello world!</strong>'); | ||
expect(pen.toString(), 'to equal', | ||
'<code>\n' + | ||
' <div><strong>Hello world!</strong></div>\n' + | ||
'</code>'); | ||
``` | ||
### newline(), nl() | ||
Starts a new line. | ||
### Indentation | ||
Example: | ||
```js | ||
pen.text('Hello').nl() | ||
.indentLines() | ||
.indent().text('beautiful').nl() | ||
.outdentLines() | ||
.text('world'); | ||
expect(pen.toString(), 'to equal', | ||
'Hello\n' + | ||
' beautiful\n' + | ||
'world'); | ||
``` | ||
#### indentLines() | ||
Increments the indentation level. | ||
#### outdentLines() | ||
Decrements the indentation level. | ||
#### indent(), i() | ||
Appends the indentation to the output. | ||
### append(pen) | ||
Appends the content of the given pen to the end of this pen. | ||
Notice, that the given pen must be in the same mode as this pen. | ||
Example: | ||
```js | ||
var pen = magicpen(); | ||
var otherPen = pen.clone().text('world!'); | ||
pen.text('Hello').sp().append(otherPen); | ||
expect(pen.toString(), 'to equal', 'Hello world!'); | ||
``` | ||
### block(pen) | ||
Appends the content of the given pen to the end of this pen in an | ||
inline block. | ||
Notice, that the given pen must be in the same mode as this pen. | ||
Example: | ||
```js | ||
var pen = magicpen(); | ||
var otherPen = pen.clone() | ||
.text(' // This is a').nl() | ||
.text(' // multiline block'); | ||
pen.text('Text before block').block(otherPen); | ||
expect(pen.toString(), 'to equal', | ||
'Text before block // This is a\n' + | ||
' // multiline block'); | ||
``` | ||
### prependLinesWith(pen) | ||
Prepends each line of this pen with the content of the given pen. | ||
Notice, that the given pen must be in the same mode as this pen. | ||
Example: | ||
```js | ||
var pen = magicpen(); | ||
var otherPen = pen.clone().text('> '); | ||
pen.text('Line').nl() | ||
.text('after line').nl() | ||
.text('after line'); | ||
expect(pen.toString(), 'to equal', | ||
'> Line\n' + | ||
'> after line\n' + | ||
'> after line'); | ||
``` | ||
### clone() | ||
Returns a clone of the current pen with an empty output buffer. This | ||
operation is very cheap, so don't hesitate to use it when it makes | ||
sense. | ||
### addStyle(style, handler) | ||
Defines a new style for the magicpen. The usage is best explained by | ||
an example: | ||
```js | ||
var pen = magicpen('ansi'); | ||
pen.addStyle('rainbow', function (text, rainbowColors) { | ||
rainbowColors = rainbowColors || | ||
['gray', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan']; | ||
for (var i = 0; i < text.length; i += 1) { | ||
var color = rainbowColors[i % rainbowColors.length]; | ||
this.text(text[i], color); | ||
} | ||
}); | ||
pen.rainbow('The unicorns are flying low today').nl(); | ||
.rainbow('The unicorns are flying low today', ['green', 'red', 'cyan']); | ||
console.log(pen.toString()); | ||
``` | ||
![The unicors are flying low today](images/rainbows.png) | ||
As you can see in the example above, a custom style can produce any | ||
kind of output using an instance of a magicpen. | ||
## Aliases | ||
### space(count = 1), sp(count = 1) | ||
Alias for `text(duplicate(' ', count))`. | ||
### bold(content) | ||
Alias for `text(content, 'bold')`. | ||
### dim(content) | ||
Alias for `text(content, 'dim')`. | ||
### italic(content) | ||
Alias for `text(content, 'italic')`. | ||
### underline(content) | ||
Alias for `text(content, 'underline')`. | ||
### inverse(content) | ||
Alias for `text(content, 'inverse')`. | ||
### hidden(content) | ||
Alias for `text(content, 'hidden')`. | ||
### strikeThrough(content) | ||
Alias for `text(content, 'strikeThrough')`. | ||
### black(content) | ||
Alias for `text(content, 'black')`. | ||
### red(content) | ||
Alias for `text(content, 'red')`. | ||
### green(content) | ||
Alias for `text(content, 'green')`. | ||
### yellow(content) | ||
Alias for `text(content, 'yellow')`. | ||
### blue(content) | ||
Alias for `text(content, 'blue')`. | ||
### magenta(content) | ||
Alias for `text(content, 'magenta')`. | ||
### cyan(content) | ||
Alias for `text(content, 'cyan')`. | ||
### white(content) | ||
Alias for `text(content, 'white')`. | ||
### gray(content) | ||
Alias for `text(content, 'gray')`. | ||
### bgBlack(content) | ||
Alias for `text(content, 'bgBlack')`. | ||
### bgRed(content) | ||
Alias for `text(content, 'bgRed')`. | ||
### bgGreen(content) | ||
Alias for `text(content, 'bgGreen')`. | ||
### bgYellow(content) | ||
Alias for `text(content, 'bgYellow')`. | ||
### bgBlue(content) | ||
Alias for `text(content, 'bgBlue')`. | ||
### bgMagenta(content) | ||
Alias for `text(content, 'bgMagenta')`. | ||
### bgCyan(content) | ||
Alias for `text(content, 'bgCyan')`. | ||
### bgWhite(content) | ||
Alias for `text(content, 'bgWhite')`. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
65281
0
11
826
336
0
7
1
- Removedmocha@^1.20.1
- Removedunexpected@^3.2.2
- Removedcommander@0.6.12.3.0(transitive)
- Removeddebug@2.0.0(transitive)
- Removeddiff@1.0.8(transitive)
- Removedescape-string-regexp@1.0.2(transitive)
- Removedglob@3.2.3(transitive)
- Removedgraceful-fs@2.0.3(transitive)
- Removedgrowl@1.8.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjade@0.26.3(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.2.14(transitive)
- Removedminimist@0.0.8(transitive)
- Removedmkdirp@0.3.00.5.0(transitive)
- Removedmocha@1.21.5(transitive)
- Removedms@0.6.2(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedunexpected@3.2.4(transitive)