2.0.2 • Published 7 years ago

pure-formatters v2.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Pure Formatters

Build Status

A collection of pure JS functions that return formatted data. Useful in any view engine.

Installation

Node.js

> npm install --save pure-formatters

Browser

<script src="node_modules/pure-formatters/dist/pure-formatters.js"></script>

<!-- Or CDN -->
<script src="https://unpkg.com/pure-formatters/dist/pure-formatters.js"></script>

Usage

Browser

// After adding script tag, the global variable pf is available
console.log(pf.upperCase('hello world'));

Node.js

const pf = require('pure-formatters');

console.log(pf.upperCase('hello world'));

React

import { Component } from 'react';
import { upperCase } from 'pure-formatters';

class App extends Component {
  render() {
    return (
      <div>
        {upperCase('hello world')}
      </div>
    );
  }
}

export default App;

Vue

<template>
  <div>
    {{ msg | upperCase }}
  </div>
</template>

<script>
import { upperCase } from 'pure-formatters';

export default {
  name: 'component-name',
  data() {
    return { msg: 'hello world' },
  },
  filters: {
    upperCase,
  },
};
</script>

Formatters

SymbolDescriptionInputOutput
camelCaseConverts string to camel case.'Foo Bar''fooBar'
'--foo-bar--''fooBar'
'__FOO_BAR__''fooBar'
capitalizeConverts the first character of string to upper case and the remaining to lower case'FRED''Fred'
deburrDeburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.'déjà vu''deja vu'
displayNullIf input is null or '', return 'null''''null'
'Hello World''Hello World'
'', 'empty''empty'
escapeConverts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.'fred, barney, & pebbles''fred, barney, & pebbles'
escapeRegExpEscapes the RegExp special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "", "", "{", "}", and "|" in string.'[lodash](htttps://lodash.com/)''\lodash\\(htttps://lodash\.com/\)'
kebabCaseConverts string to kebab case.'Foo Bar''foo-bar'
'fooBar''foo-bar'
'__FOO_BAR__''foo-bar'
lowerCaseConverts string, as space separated words, to lower case.'--Foo-Bar--''foo bar'
'fooBar''foo bar'
'__FOO_BAR__''foo bar'
lowerFirstConverts the first character of string to lower case.'Fred''fred'
'FRED''fRED'
padPads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.'abc', 8' abc '
'abc', 8, '_-''-abc-_'
'abc', 3'abc'
sentenceListCombines array elements with commas and "and"'Bettye Norton''Bettye Norton'
'Bettye Norton', 'Melisa Reed''Bettye Norton and Melisa Reed'
'Bettye Norton', 'Melisa Reed', 'Kari Osborne''Bettye Norton, Melisa Reed, and Kari Osborne'
{ name: 'Bettye Norton' }, 'name''Bettye Norton'
upperCaseConverts string, as space separated words, to upper case.'--foo-bar''FOO BAR'
'fooBar''FOO BAR'
'__foo_bar__''FOO BAR'
usdAdds a dollar sign and rounds to 2 decimal places1.5'$1.50'
150, 'c''$1.50'
padEndDescription, input, and output coming soon.
padStartDescription, input, and output coming soon.
repeatDescription, input, and output coming soon.
replaceDescription, input, and output coming soon.
snakeCaseDescription, input, and output coming soon.
startCaseDescription, input, and output coming soon.
toLowerDescription, input, and output coming soon.
toUpperDescription, input, and output coming soon.
trimDescription, input, and output coming soon.
trimEndDescription, input, and output coming soon.
trimStartDescription, input, and output coming soon.
truncateDescription, input, and output coming soon.
unescapeDescription, input, and output coming soon.
upperFirstDescription, input, and output coming soon.

Contributing

See CONTRIBUTING.md

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago