Action

Reverse First and Last Name

Last update 28 days ago

Given a list of full names the first names and last names will be reversed. Commas will added or removed depending on if they are in the original name.

Foo Bar becomes Bar, Foo and vice versa.

Steps

  • script

    // See online documentation for examples
    // https://docs.getdrafts.com/docs/actions/scripting
    
    // See online documentation for examples
    // https://docs.getdrafts.com/docs/actions/scripting
    
    // See online documentation for examples
    // http://getdrafts.com/scripting
    
    var d = Draft.create();
    // var d = draft;
    var l = draft.content.split('\n');
    var content = ""
    
    for (var i=0; i<l.length; i++) {
    var line=l[i]
    
    var sep =
    /\,/.test(line)?' ':', '
    
     if (line) {
        line=line.replaceAll(',','')
        var name = line.split(' ')
        content = content + name[1] + sep + name[0] + "\n"
        }
    }
    draft.content = content
    draft.update();
    
    script.complete()

Options

  • After Success Nothing
    Notification None
    Log Level None
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.