Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Griffiths <mark@thebespokepixel.com>
  • Loading branch information
MarkGriffiths committed Apr 22, 2016
0 parents commit bf6251f
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
root = true

# Unix-style newlines with a newline ending every file
# with no excess whitespace ending lines, no indentation preference.
[*]
charset = utf8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# 2 spaces for list indenting, 2 'tabs' for code blocks if not fenced.
# Don't trim line whitespace as it's significant in markdown.
[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.{yaml,yml}]
indent_style = space
indent_size = 2

# A personal preference for hybrid indentation in sources I generate:
# Tabs for indent, spaces for alignment. It's the typeographer in me.
# Tab width of 3 is my 'Goldilocks' zone of indentation and until I can grep
# indention spaces explicitly, Tabs it will be. Opinionated? Absolutely!
[*.{coffee,js,JavaScript,json,c,h,ino,cpp,fish,sh,pl,py}]
indent_style = tab
indent_size = 3

[package.json]
insert_final_newline = false
indent_style = space
indent_size = 2

[.eslintrc.{js,json}]
indent_style = space
indent_size = 2

# 2 space indents when required. rc's should really be in package.json
[{.esformatter,.jshintrc}]
indent_style = space
indent_size = 2
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.npmignore
src
test
*.sublime*
.editorconfig
.travis.yml
gulpfile.*
*.map
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: node_js
node_js:
- stable
sudo: false
before_install: npm i -g npm@latest
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/d0418713e51ac049564a
on_success: always
on_failure: change
on_start: never
37 changes: 37 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'
/*
* Client Gulp File
*/

const gulp = require('gulp')
const cordial = require('@thebespokepixel/cordial')

// Default
gulp.task('default', ['babel-format'])

// Versioning
gulp.task('bump', cordial.version.build.inc)
gulp.task('reset', cordial.version.build.reset)
gulp.task('write', cordial.version.build.write)

// Comtranspilationatting
gulp.task('babel', ['bump', 'write'], cordial.compile.babel(['src/**/*.js'], './'))
gulp.task('babel-format', ['bump', 'write'], cordial.format.babel(['src/**/*.js'], './'))

// Tests
gulp.task('test', ['xo'], cordial.test.ava(['test/*']))
gulp.task('xo', cordial.test.xo(['src/**/*.js', 'lib/**/*.js', 'index.js']))

// Git
gulp.task('commit', cordial.git.commitAll)
gulp.task('push', cordial.git.pushAll('origin'))
gulp.task('backup', ['push'], cordial.git.pushAll('backup'))

// npm
gulp.task('publish', ['test'], cordial.npm.publish)

// Guppy Hooks
gulp.task('post-flow-release-start', ['reset', 'write'], cordial.flow.release.start)
gulp.task('post-flow-release-finish', ['publish', 'push'])
gulp.task('filter-flow-release-start-version', cordial.flow.release.versionFilter)
gulp.task('filter-flow-release-finish-tag-message', cordial.flow.release.tagFilter)
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

/*
@thebespokepixel/number
Esoteric string formatting
*/

exports.pad = (string_, char_, length_) => {
return length_ > 0 ? (char_.repeat(length_) + string_).slice(-length_) : (string_ + char_.repeat(-length_)).slice(0, -length_)
}

exports.toSub = string_ => {
const charsO = '₀₁₂₃₄₅₆₇₈₉₊₋₌₌. ₐₓₓₓₑₓₓₕᵢⱼₖₗₘₙₒₚₓᵣₛₜᵤᵥₓₓₓₓ₍₎ᴀʙcᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ╷╷'
const charsI = '0123456789+-=:. abcdefghijklmnopqrstuvwxyz()ABCDEFGHIJKLMNOPQRSTUVWXYZ/|'
let output = ''
string_.split('').forEach(digit_ => {
output += charsO[charsI.indexOf(digit_)]
})
return output
}

exports.toSuper = string_ => {
const charsO = '⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁼⋅ ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖᵍʳˢᵗᵘᵛʷˣʸᶻ⁽⁾ᴬᴮᶜᴰᴱᶠᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴼᴿˢᵀᵁⱽᵂˣʸᶻ╵╵'
const charsI = '0123456789+-=:. abcdefghijklmnopqrstuvwxyz()ABCDEFGHIJKLMNOPQRSTUVWXYZ/|'
let output = ''
string_.split('').forEach(digit_ => {
output += charsO[charsI.indexOf(digit_)]
})
return output
}
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@thebespokepixel/string",
"version": "0.0.1",
"description": "Bespoke extensions of the String object",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"@thebespokepixel/cordial": "^0.9.1"
},
"scripts": {
"test": "ava"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MarkGriffiths/string.git"
},
"keywords": [
"cli",
"banner",
"title",
"titling"
],
"author": "Mark Griffiths <mark@thebespokepixel.com> (http://thebespokepixel.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/MarkGriffiths/bespoke-string/issues"
},
"homepage": "https://github.com/MarkGriffiths/bespoke-string#readme",
"xo": {
"semicolon": false,
"esnext": true
},
"ava": {
"files": [
"test/*.js"
]
},
"build_number": 174
}
31 changes: 31 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Bespoke String Extensions
>A augmented drop-in console replacement that supports logging levels.
>
>![Project status][project-badge]
[![npm Status][npm-badge]][npm]
[![XO code style][xo-badge]][xo]
[![Chat on Gitter][gitter-badge]][gitter]
[![Build Status][build-badge]][travis]
[![Dependency Status][david-badge]][david]
[![devDependency Status][david-dev-badge]][david-dev]

### Install

```sh
npm install @thebespokepixel/strings --save
```

[project-badge]: http://img.shields.io/badge/status-alpha-red.svg?style=flat
[build-badge]: http://img.shields.io/travis/MarkGriffiths/bespoke-strings.svg?branch=master&style=flat
[david-badge]: http://img.shields.io/david/MarkGriffiths/bespoke-strings.svg?style=flat
[david-dev-badge]: http://img.shields.io/david/dev/MarkGriffiths/bespoke-strings.svg?style=flat
[npm-badge]: https://img.shields.io/npm/v/bespoke-strings.svg?style=flat
[xo-badge]: https://img.shields.io/badge/code_style-XO-5ed9c7.svg
[gitter-badge]: https://badges.gitter.im/MarkGriffiths/help.svg

[travis]: https://travis-ci.org/MarkGriffiths/bespoke-strings
[david]: https://david-dm.org/MarkGriffiths/bespoke-strings
[david-dev]: https://david-dm.org/MarkGriffiths/bespoke-strings#info=devDependencies
[npm]: https://www.npmjs.com/package/@thebespokepixel/bespoke-strings
[xo]: https://github.com/sindresorhus/xo
[gitter]: https://gitter.im/MarkGriffiths/help?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
31 changes: 31 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
@thebespokepixel/number
Esoteric string formatting
*/

exports.pad = (string_, char_, length_) => {
return (length_ > 0) ?
(char_.repeat(length_) + string_).slice(-length_) :
(string_ + char_.repeat(-length_)).slice(0, -length_)
}

exports.toSub = string_ => {
const charsO = '₀₁₂₃₄₅₆₇₈₉₊₋₌₌. ₐₓₓₓₑₓₓₕᵢⱼₖₗₘₙₒₚₓᵣₛₜᵤᵥₓₓₓₓ₍₎ᴀʙcᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ╷╷'
const charsI = '0123456789+-=:. abcdefghijklmnopqrstuvwxyz()ABCDEFGHIJKLMNOPQRSTUVWXYZ/|'
let output = ''
string_.split('').forEach(digit_ => {
output += charsO[charsI.indexOf(digit_)]
})
return output
}

exports.toSuper = string_ => {
const charsO = '⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁼⋅ ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖᵍʳˢᵗᵘᵛʷˣʸᶻ⁽⁾ᴬᴮᶜᴰᴱᶠᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴼᴿˢᵀᵁⱽᵂˣʸᶻ╵╵'
const charsI = '0123456789+-=:. abcdefghijklmnopqrstuvwxyz()ABCDEFGHIJKLMNOPQRSTUVWXYZ/|'
let output = ''
string_.split('').forEach(digit_ => {
output += charsO[charsI.indexOf(digit_)]
})
return output
}

30 changes: 30 additions & 0 deletions test/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

import test from 'ava'
import bString from '..'

test(`Basic digits 123... → ¹²³⋅⋅⋅/₁₂₃...`, t => {
t.plan(2)
t.is(bString.toSub('1234567890'), '₁₂₃₄₅₆₇₈₉₀')
t.is(bString.toSuper('1234567890'), '¹²³⁴⁵⁶⁷⁸⁹⁰')
})

test(`Pangram → ᵀʰᵉ/ᴛₕₑ`, t => {
const pangram = 'The quick brown fox jumps over the lazy dog.'
t.plan(2)
t.is(bString.toSub(pangram), 'ᴛₕₑ ₓᵤᵢₓₖ ₓᵣₒₓₙ ₓₒₓ ⱼᵤₘₚₛ ₒᵥₑᵣ ₜₕₑ ₗₐₓₓ ₓₒₓ.')
t.is(bString.toSuper(pangram), 'ᵀʰᵉ ᵍᵘⁱᶜᵏ ᵇʳᵒʷⁿ ᶠᵒˣ ʲᵘᵐᵖˢ ᵒᵛᵉʳ ᵗʰᵉ ˡᵃᶻʸ ᵈᵒᵍ⋅')
})

test(`Basic padding 12345/◌ 10 chars (left pad)`, t => {
t.is(bString.pad('12345', ' ', 10), ' 12345')
})

test(`Basic padding 12345/◌ -10 chars (right pad)`, t => {
t.is(bString.pad('12345', ' ', -10), '12345 ')
})

test(`Long arrow padding →/– 8 chars`, t => {
t.is(bString.pad('→', '–', 8), '–––––––→')
})

0 comments on commit bf6251f

Please sign in to comment.