0.0.2 • Published 6 years ago

trim-everything v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

trim-everything

trim everything without methods because i use JSON.stringify and JSON.parse to trim

Features

  • trim undefined
  • trim null
  • trim number
  • trim string
  • trim object
  • trim array
  • zero dependencies

Getting Started

/* global test, expect */
const trim = require('trim-everything')

test('trim undefined', () => {
  expect(trim()).toBeUndefined()
})

test('trim null', () => {
  expect(trim(null)).toBeNull()
})

test('trim number', () => {
  expect(trim(12.12)).toBe(12.12)
})

test('trim string', () => {
  expect(trim(' 12abcd ')).toBe('12abcd')
})

test('trim object', () => {
  expect(trim({
    userName: ' wangdd ',
    age: 12,
    some: false,
    address: ' shanghai'
  }))
  .toEqual({
    userName: 'wangdd',
    age: 12,
    some: false,
    address: 'shanghai'
  })
})

test('trim array', () => {
  expect(trim([
    {
      userName: ' wangdd ',
      age: 12,
      some: false,
      address: ' shanghai'
    },
    ' abcd ',
    false,
    12.12,
    {
      userName: ' wangdd ',
      age: 12,
      some: false,
      address: ' shanghai',
      child: {
        userName: ' wangdd ',
        age: 12,
        some: false,
        address: ' shanghai'
      }
    }
  ]))
  .toEqual(
    [
      {
        userName: 'wangdd',
        age: 12,
        some: false,
        address: 'shanghai'
      },
      'abcd',
      false,
      12.12,
      {
        userName: 'wangdd',
        age: 12,
        some: false,
        address: 'shanghai',
        child: {
          userName: 'wangdd',
          age: 12,
          some: false,
          address: 'shanghai'
        }
      }
    ]
  )
})