npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

cut-head

1.0.0 • Public • Published
cutHead = (str, delimeter)-> 
  unless str
    return [undefined, undefined]
  index = str.indexOf delimeter 
  if index > 0
    head = str.substr(0, index) 
    others = str.substr(index + 1)
    others = undefined if others.length is 0 
    return [head, others]
  return [str, undefined]

cutHead = require '../src'

describe 'cutHead', ()->
  it 'head#others', (done)->
    [head, others] = cutHead 'head#others', '#'  
 
    expect head
      .toEqual 'head'
    expect others
      .toEqual 'others' 
    done()
 
  it 'head', (done)->
    [head, others] = cutHead 'head', '#'  
 
    expect head
      .toEqual 'head'
    expect others
      .toEqual undefined 
    done()  
 
  it 'head#', (done)->
    [head, others] = cutHead 'head#', '#'  
 
    expect head
      .toEqual 'head'
    expect others
      .toEqual undefined 
    done()

 
  it 'null', (done)->
    [head, others] = cutHead null, '#'  
 
    expect head
      .toEqual undefined
    expect others
      .toEqual undefined 
    done() 
 
  it 'undefined', (done)->
    [head, others] = cutHead undefined, '#'  
 
    expect head
      .toEqual undefined
    expect others
      .toEqual undefined 
    done()

install

npm i cut-head

Downloadsweekly downloads

1

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability