• Jump To … +
    backer-util.coffee badge-util.coffee history-util.coffee install-util.coffee license-util.coffee projectz-util.coffee projectz.litcoffee
  • projectz-util.coffee

  • ¶

    Import

    typeChecker = require('typechecker')
  • ¶

    Utils

    module.exports = projectzUtil =
  • ¶

    Get Person Text

    	getPersonText: (person) ->
    		return person.markdown or person.text or person
  • ¶

    Get File URL

    	getFileUrl: (opts, filename) ->
    		url = "https://github.com/#{opts.username}/#{opts.name}/blob/master/#{filename}#files"
    		return url
  • ¶

    Get Function Named e.g. {getMitLicense,getLicenses} with 'mit' returns getMitLicense

    	getFunctionNamed: (str) ->
  • ¶

    Prepare

    		str = str.toLowerCase()
  • ¶

    Find

    		for own name,fn of @
    			if name.substr(3).substr(str.length*-1).toLowerCase() is str
    				return fn
  • ¶

    Return

    		return null
  • ¶

    Get Functions Ending With e.g. {getNpmBadge,getBadges} with 'Badge' returns [getNpmBadge]

    	getFunctionsEndingWith: (str) ->
  • ¶

    Prepare

    		fns = []
  • ¶

    Find

    		for own name,fn of @
    			if name.substr(str.length*-1) is str
    				fns.push(fn)
  • ¶

    Return

    		return fns
  • ¶

    Replace Section

    	replaceSection: (names, source, inject) ->
    		if typeChecker.isArray(names)
    			regexName = '('+names.join('|')+')'
    			sectionName = names[0]
    		else
    			regexName = sectionName = names
    
    		sectionName = sectionName.toUpperCase()
    
    		regex = ///
    			\n(
    				<!--\s*#{regexName}\s*-->
    				|
    				<!--\s*#{regexName}/\s*-->
    				[\s\S]*?
    				<!--\s*/#{regexName}\s*-->
    			)\s*
    			///gim
    
    		replace = """
    			\n<!-- #{sectionName}/ -->\n\n#{inject}\n\n<!-- /#{sectionName} -->\n\n\n
    			"""
    
    		result = source.replace(regex, replace)
    
    		return result