Code Monkey home page Code Monkey logo

fingerprint's Introduction

Fingerprint

Fingeprint objects and arrays.

Usage

This library can be used to create a fingerprint for: Objects, Arrays and primitives such as String and Number. You can combine these fingerprinting techniques to create fingerprints for complex, composite object structures and thus create a unique fingerprint for any data-structure. This technique is often used for caching purposes.

Permit-Authorize uses fingerprinting for its caching, mostly to identify repeated access requests and then returning the cached authorization result for that fingerprint instead of recalculating which drastically improves authorization performance!

Array

finger-printer = (array) ->
  new ArrayFingerPrint array

access-request := ['hello', 'goodbye']

finger-printer(access-request).fingerprint!

Object

finger-printer = (obj) ->
  new ObjectFingerPrint obj

access-request := {subject: subj, role: 'editor', object: post, ctx: 'admin'}

finger-printer(access-request).fingerprint!`

For any object, the ObjectFingerPrint will try to call a hash function on the object if available, then a fingerprint function and finally fall back to doing a JSON stringify that is md5'ed.

This is in order to avoid expensive hash calculations for each object. Say you have a user object, it is much more efficient to add a fingerprint method which returns the unique id or email as the fingerprint key.

TODO

Add Fingerprint method to fingerprint an Object or Array recursively.

Licence

MIT License Copyright 2014-2015 Kristian Mandrup

See LICENSE file

fingerprint's People

Contributors

kristianmandrup avatar

Watchers

 avatar  avatar  avatar

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.