peoplestring-stringify

1.0.0 • Public • Published

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: 'mary@smith.com' }),
  'Mary Smith <mary@smith.com>')

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: 'mary@smith.com',
      url: 'https://marysmith.com' }),
  'Mary Smith <mary@smith.com> (https://marysmith.com)')

A peoplestring can contain just an e-mail address in angle brackets.

assert.equal(
  stringify({ email: 'mary@smith.com' }),
  '<mary@smith.com>')

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!') })

Readme

Keywords

none

Package Sidebar

Install

npm i peoplestring-stringify

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • kemitchell