peoplestring-stringify
v1.0.0
Published
generate strings like "Mary Smith <[email protected]> (https://marysmith.com) [SomeCo, Inc.]"
Downloads
4
Readme
The package exports a single function.
var stringify = require('peoplestring-stringify')
The function takes a single Object
argument with any number of the
following properties: name
, email
, url
, and for
. It returns a
string that peoplestring-parse can read.
The following examples are also the test suite for the package. They use
Node.js' built-in assert
module.
var assert = require('assert')
A peoplestring can contain just a name.
assert.equal(
stringify({ name: 'Mary Smith' }),
'Mary Smith')
If the name has trailing whitespace, it's ignored.
assert.equal(
stringify({ name: 'Mary Smith ' }),
'Mary Smith')
If the name has leading whitespace, it's ignored.
assert.equal(
stringify({ name: ' Mary Smith' }),
'Mary Smith')
A peoplestring can contain an e-mail address in angle brackets.
assert.equal(
stringify(
{ name: 'Mary Smith',
email: '[email protected]' }),
'Mary Smith <[email protected]>')
A peoplestring can contain a URL in parentheses.
assert.equal(
stringify({ name: 'Mary Smith',
url: 'https://marysmith.com' }),
'Mary Smith (https://marysmith.com)')
A peoplestring can contain the name of another person or company to show a person's contribution is a work made for hire for someone else.
assert.equal(
stringify(
{ name: 'Mary Smith',
for: 'SuperCo, Inc.' }),
'Mary Smith [SuperCo, Inc.]')
A peoplestring can contain a name, an e-mail address, and a URL.
assert.equal(
stringify(
{ name: 'Mary Smith',
email: '[email protected]',
url: 'https://marysmith.com' }),
'Mary Smith <[email protected]> (https://marysmith.com)')
A peoplestring can contain just an e-mail address in angle brackets.
assert.equal(
stringify({ email: '[email protected]' }),
'<[email protected]>')
A peoplestring can contain just a URL in parentheses.
assert.equal(
stringify({ url: 'https://marysmith.com' }),
'(https://marysmith.com)')
A peoplestring can contain just the name of the work make for hire owner.
assert.equal(
stringify({ for: 'SuperCo, Inc.' }),
'[SuperCo, Inc.]')
The function throws when passed a non-string arguments.
assert.throws(
function () {
stringify('already a string!') })