one-dollar
v2.1.0
Published
$1 - Shape recognition
Downloads
30
Readme
$1 for Node/browserify
This is a simple wrapper around shape detector library $1 (1dollar.js).
Install
npm install one-dollar
Usage
Verbose (original API)
const OneDollar = require('one-dollar')
const recognizer = new OneDollar.DollarRecognizer()
const result = recognizer.Recognize([
new Recognizer.Point(1, 2),
new Recognizer.Point(10, 3),
new Recognizer.Point(12, 27),
new Recognizer.Point(3, 25),
new Recognizer.Point(0, 0)
])
console.log(result)
// Result { Name: 'caret', Score: 0.7524355578423304 }
Shorter API
Original API is quite weird : force using new Point
s, title-cased methods… and it's way too verbose.
This module proposes a shortcut for faster access to what you want:
const OneDollar = require('one-dollar')
const recognize = OneDollar()
const result = recognize([[1, 2], [10, 3], [12, 27], [3, 25], [0, 0]])
console.log(result)
// Result { name: 'caret', score: 0.7524355578423304 }
Differences from original API:
- no
new OneDollar.DollarRecognizer
, the function returns directly a recognition function- This function accepts
[x, y]
instead ofnew OneDollar.Point(x, y)
(you can still instanciate points, if you really want) - This function returns object with lower-cased properties (
{name, score}
instead of{Name, Score}
) - In case of no match, the result's name is
nomatch
instead ofNo match.
- This function accepts
- you still have access to original methods, but they're camelcased:
recognize.recognize
instead ofrecognizer.Recognize
recognize.addGesture
instead ofrecognizer.AddGesture
recognize.deleteUserGestures
instead ofrecognizer.DeleteUserGestures
recognize.gestures
instead ofrecognizer.Unistrokes
to list user gestures- Note that those methods are the original ones, and will require
Point
instances