GithubHelp home page GithubHelp logo

callback-string's Introduction

callback-string

js-standard-style Build Status

callback-string can be useful if you are using a command pattern approach or RPC or simply when you need to save a callback to call later (see Facebook Messenger postback). callback-string has only two method, parse and stringify, the first transforms a callback object to the respective string, the second viceversa.

Example:

const parse = require('callback-string/Parse')
const stringify = require('callback-string/Stringify')

const obj = {
  callback: 'getData',
  parameters: {
    from: '10/02/2002',
    to: '11/03/2008'
  }
}

const str = stringify(obj).result
console.log(str) // getData#from=10/02/2002#to=11/03/2008

const objParsed = parse(obj)
console.log(objParsed)

As you can see it expects that the object to stringify is formatted in this way:

const obj = {
  callback: 'actionName', // string
  parameters: {         // object
    par1: 'par1',       // any type
    par2: 2             // any type
  }
}

const str = 'actionName#par1=par1#par2=2'

Install

npm install callback-string --save

Usage

parse(callbackString, escape)

callbackString must be a string
escape must be a string, default to '#'
Returns an object formatted as described above.

stringify(callbackObject, escape)

callbackObject must be an object as described above
escape must be a string, default to '#'
Returns a string formatted as described above.

Contributing

If you feel you can help in any way, be it with examples, extra testing, or new features please open a pull request or open an issue.

The code follows the Standard code style.
js-standard-style

License

MIT

The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

Copyright © 2016 Tomas Della Vedova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.