Initial commit: n8n Strike API node

- Add Strike API credentials configuration
- Implement Strike node with 9 resources (Account, Balance, Currency Exchange, Deposit, Invoice, Payment, Payment Method, Payout, Rates)
- Add comprehensive operation descriptions for all resources
- Include CLAUDE.MD documentation
- Set up build configuration with TypeScript, ESLint, and Prettier

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-10 11:00:38 +01:00
commit 5605b9b49a
8925 changed files with 1417728 additions and 0 deletions

21
node_modules/undertaker/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Blaine Bublitz, Eric Schoffstall and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 NONINFRINGEMENT. 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.

324
node_modules/undertaker/README.md generated vendored Normal file
View File

@ -0,0 +1,324 @@
<p align="center">
<a href="http://gulpjs.com">
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
</a>
</p>
# undertaker
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
## Usage
```js
var fs = require('fs');
var Undertaker = require('undertaker');
var taker = new Undertaker();
taker.task('task1', function(cb){
// do things
cb(); // when everything is done
});
taker.task('task2', function(){
return fs.createReadStream('./myFile.js')
.pipe(fs.createWriteStream('./myFile.copy.js'));
});
taker.task('task3', function(){
return new Promise(function(resolve, reject){
// do things
resolve(); // when everything is done
});
});
taker.task('combined', taker.series('task1', 'task2'));
taker.task('all', taker.parallel('combined', 'task3'));
```
## API
__Task functions can be completed in any of the ways supported by
[`async-done`][async-resolution]__
### `new Undertaker([registryInstance])`
The constructor is used to create a new instance of `Undertaker`. Each instance of
`Undertaker` gets its own instance of a registry. By default, the registry is an
instance of [`undertaker-registry`][undertaker-registry]
but it can be an instance of any other registry that follows the [Custom Registries API][custom-registries].
To use a custom registry, pass a custom registry instance (`new CustomRegistry([options])`) when
instantiating a new `Undertaker` instance. This will use the custom registry instance for that `Undertaker` instance.
### `task([taskName,] fn)`
Both a `getter` and `setter` for tasks.
If a string (`taskName`) is given as the only argument, it behaves as a `getter`
and returns the wrapped task (not the original function). The wrapped task has a `unwrap`
method that will return the original function.
If a function (`fn`) and optionally a string (`taskName`) is given, it behaves as
a `setter` and will register the task by the `taskName`. If `taskName` is not
specified, the `name` or `displayName` property of the function is used as the `taskName`.
Will throw if:
* As a `getter`: `taskName` is missing or not a string.
* As a `setter`: `taskName` is missing and `fn` is anonymous.
* As a `setter`: `fn` is missing or not a function.
### `series(taskName || fn...)`
Takes a variable amount of strings (`taskName`) and/or functions (`fn`) and
returns a function of the composed tasks or functions. Any `taskNames` are
retrieved from the registry using the `get` method.
When the returned function is executed, the tasks or functions will be executed
in series, each waiting for the prior to finish. If an error occurs, execution
will stop.
### `parallel(taskName || fn...)`
Takes a variable amount of strings (`taskName`) and/or functions (`fn`) and
returns a function of the composed tasks or functions. Any `taskNames` are
retrieved from the registry using the `get` method.
When the returned function is executed, the tasks or functions will be executed
in parallel, all being executed at the same time. If an error occurs, all execution
will complete.
### `registry([registryInstance])`
Optionally takes an instantiated registry object. If no arguments are passed, returns
the current registry object. If an instance of a registry (`customRegistry`) is passed
the tasks from the current registry will be transferred to it and the current registry
will be replaced with the new registry.
The ability to assign new registries will allow you to pre-define/share tasks or add
custom functionality to your registries. See [Custom Registries][custom-registries]
for more information.
### `tree([options])`
Optionally takes an `options` object and returns an object representing the
tree of registered tasks. The object returned is [`archy`][archy]
compatible. Also, each node has a `type` property that can be used to determine if the node is a `task` or `function`.
#### `options`
##### `options.deep`
Whether or not the whole tree should be returned.
Type: `Boolean`
Default: `false`
### `lastRun(task, [precision])`
Takes a string or function (`task`) and returns a timestamp of the last time the task
was run successfully. The time will be the time the task started.
Returns `undefined` if the task has not been run.
If a task errors, the result of `lastRun` will be undefined because the task
should probably be re-run from scratch to get into a good state again.
The timestamp is always given in millisecond but the time resolution can be
rounded using the `precision` parameter. The use case is to be able to compare a build time
to a file time attribute. On node v0.10 or with file system like HFS or FAT,
`fs.stat` time attributes like `mtime` precision is one second.
Assuming `undertakerInst.lastRun('someTask')` returns `1426000001111`,
`undertakerInst.lastRun('someTask', 1000)` returns `1426000001000`.
The default time resolution is `1000` on node v0.10, `0` on node 0.11+ but
it can be overwritten using `UNDERTAKER_TIME_RESOLUTION` environment variable.
## Custom Registries
Custom registries are constructor functions allowing you to pre-define/share tasks
or add custom functionality to your registries.
A registry's prototype should define:
- `init(taker)`: receives the undertaker instance to set pre-defined tasks using the `task(taskName, fn)` method.
- `get(taskName)`: returns the task with that name
or `undefined` if no task is registered with that name.
- `set(taskName, fn)`: add task to the registry. If `set` modifies a task, it should return the new task.
- `tasks()`: returns an object listing all tasks in the registry.
You should not call these functions yourself; leave that to Undertaker, so it can
keep its metadata consistent.
The easiest way to create a custom registry is to inherit from [undertaker-registry]:
```js
var util = require('util');
var DefaultRegistry = require('undertaker-registry');
function MyRegistry(){
DefaultRegistry.call(this);
}
util.inherits(MyRegistry, DefaultRegistry);
module.exports = MyRegistry;
```
### Sharing tasks
To share common tasks with all your projects, you can expose an `init` method on the registry
prototype and it will receive the `Undertaker` instance as the only argument. You can then use
`undertaker.task(name, fn)` to register pre-defined tasks.
For example you might want to share a `clean` task:
```js
var fs = require('fs');
var util = require('util');
var DefaultRegistry = require('undertaker-registry');
var del = require('del');
function CommonRegistry(opts){
DefaultRegistry.call(this);
opts = opts || {};
this.buildDir = opts.buildDir || './build';
}
util.inherits(CommonRegistry, DefaultRegistry);
CommonRegistry.prototype.init = function(takerInst){
var buildDir = this.buildDir;
var exists = fs.existsSync(buildDir);
if(exists){
throw new Error('Cannot initialize common tasks. ' + buildDir + ' directory exists.');
}
takerInst.task('clean', function(){
return del([buildDir]);
});
}
module.exports = CommonRegistry;
```
Then to use it in a project:
```js
var Undertaker = require('undertaker');
var CommonRegistry = require('myorg-common-tasks');
var taker = new Undertaker(CommonRegistry({ buildDir: '/dist' }));
taker.task('build', taker.series('clean', function build(cb) {
// do things
cb();
}));
```
### Sharing Functionalities
By controlling how tasks are added to the registry, you can decorate them.
For example if you wanted all tasks to share some data, you can use a custom registry
to bind them to that data. Be sure to return the altered task, as per the description
of registry methods above:
```js
var util = require('util');
var Undertaker = require('undertaker');
var DefaultRegistry = require('undertaker-registry');
// Some task defined somewhere else
var BuildRegistry = require('./build.js');
var ServeRegistry = require('./serve.js');
function ConfigRegistry(config){
DefaultRegistry.call(this);
this.config = config;
}
util.inherits(ConfigRegistry, DefaultRegistry);
ConfigRegistry.prototype.set = function set(name, fn) {
// The `DefaultRegistry` uses `this._tasks` for storage.
var task = this._tasks[name] = fn.bind(this.config);
return task;
};
var taker = new Undertaker();
taker.registry(new BuildRegistry());
taker.registry(new ServeRegistry());
// `taker.registry` will reset each task in the registry with
// `ConfigRegistry.prototype.set` which will bind them to the config object.
taker.registry(new ConfigRegistry({
src: './src',
build: './build',
bindTo: '0.0.0.0:8888'
}));
taker.task('default', taker.series('clean', 'build', 'serve', function(cb) {
console.log('Server bind to ' + this.bindTo);
console.log('Serving' + this.build);
cb();
}));
```
### In the wild
* [undertaker-registry] - Custom registries probably want to inherit from this.
* [undertaker-forward-reference] - Custom registry supporting forward referenced tasks (similar to gulp 3.x).
* [undertaker-task-metadata] - Proof-of-concept custom registry that attaches metadata to each task.
* [undertaker-common-tasks] - Proof-of-concept custom registry that pre-defines some tasks.
* [alchemist-gulp] - A default set of tasks for building alchemist plugins.
* [gulp-hub] - Custom registry to run tasks in multiple gulpfiles. (In a branch as of this writing)
* [gulp-pipeline] - [RailsRegistry][rails-registry] is an ES2015 class that provides a gulp pipeline replacement for rails applications
## License
MIT
[downloads-image]: https://img.shields.io/npm/dm/undertaker.svg
[npm-url]: https://www.npmjs.com/package/undertaker
[npm-image]: https://img.shields.io/npm/v/undertaker.svg
[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=$PROJECT_ID&branchName=master
[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/undertaker?branchName=master
[travis-url]: https://travis-ci.org/gulpjs/undertaker
[travis-image]: https://img.shields.io/travis/gulpjs/undertaker.svg?label=travis-ci
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/undertaker
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/undertaker.svg?label=appveyor
[coveralls-url]: https://coveralls.io/r/gulpjs/undertaker
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/undertaker/master.svg
[gitter-url]: https://gitter.im/gulpjs/gulp
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg
[custom-registries]: #custom-registries
[async-resolution]: https://github.com/phated/async-done#completion-and-error-resolution
[archy]: https://www.npmjs.org/package/archy
[undertaker-registry]: https://github.com/gulpjs/undertaker-registry
[undertaker-forward-reference]: https://github.com/gulpjs/undertaker-forward-reference
[undertaker-task-metadata]: https://github.com/gulpjs/undertaker-task-metadata
[undertaker-common-tasks]: https://github.com/gulpjs/undertaker-common-tasks
[alchemist-gulp]: https://github.com/webdesserts/alchemist-gulp
[gulp-hub]: https://github.com/frankwallis/gulp-hub/tree/registry-init
[gulp-pipeline]: https://github.com/alienfast/gulp-pipeline
[rails-registry]: https://github.com/alienfast/gulp-pipeline/blob/master/src/registry/railsRegistry.js

47
node_modules/undertaker/index.js generated vendored Normal file
View File

@ -0,0 +1,47 @@
'use strict';
var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;
var DefaultRegistry = require('undertaker-registry');
var tree = require('./lib/tree');
var task = require('./lib/task');
var series = require('./lib/series');
var lastRun = require('./lib/last-run');
var parallel = require('./lib/parallel');
var registry = require('./lib/registry');
var _getTask = require('./lib/get-task');
var _setTask = require('./lib/set-task');
function Undertaker(customRegistry) {
EventEmitter.call(this);
this._registry = new DefaultRegistry();
if (customRegistry) {
this.registry(customRegistry);
}
this._settle = (process.env.UNDERTAKER_SETTLE === 'true');
}
inherits(Undertaker, EventEmitter);
Undertaker.prototype.tree = tree;
Undertaker.prototype.task = task;
Undertaker.prototype.series = series;
Undertaker.prototype.lastRun = lastRun;
Undertaker.prototype.parallel = parallel;
Undertaker.prototype.registry = registry;
Undertaker.prototype._getTask = _getTask;
Undertaker.prototype._setTask = _setTask;
module.exports = Undertaker;

7
node_modules/undertaker/lib/get-task.js generated vendored Normal file
View File

@ -0,0 +1,7 @@
'use strict';
function get(name) {
return this._registry.get(name);
}
module.exports = get;

29
node_modules/undertaker/lib/helpers/buildTree.js generated vendored Normal file
View File

@ -0,0 +1,29 @@
'use strict';
var map = require('collection-map');
var metadata = require('./metadata');
function buildTree(tasks) {
return map(tasks, function(task) {
var meta = metadata.get(task);
if (meta) {
return meta.tree;
}
var name = task.displayName || task.name || '<anonymous>';
meta = {
name: name,
tree: {
label: name,
type: 'function',
nodes: [],
},
};
metadata.set(task, meta);
return meta.tree;
});
}
module.exports = buildTree;

View File

@ -0,0 +1,73 @@
'use strict';
var captureLastRun = require('last-run').capture;
var releaseLastRun = require('last-run').release;
var metadata = require('./metadata');
var uid = 0;
function Storage(fn) {
var meta = metadata.get(fn);
this.fn = meta.orig || fn;
this.uid = uid++;
this.name = meta.name;
this.branch = meta.branch || false;
this.captureTime = Date.now();
this.startHr = [];
}
Storage.prototype.capture = function() {
captureLastRun(this.fn, this.captureTime);
};
Storage.prototype.release = function() {
releaseLastRun(this.fn);
};
function createExtensions(ee) {
return {
create: function(fn) {
return new Storage(fn);
},
before: function(storage) {
storage.startHr = process.hrtime();
ee.emit('start', {
uid: storage.uid,
name: storage.name,
branch: storage.branch,
time: Date.now(),
});
},
after: function(result, storage) {
if (result && result.state === 'error') {
return this.error(result.value, storage);
}
storage.capture();
ee.emit('stop', {
uid: storage.uid,
name: storage.name,
branch: storage.branch,
duration: process.hrtime(storage.startHr),
time: Date.now(),
});
},
error: function(error, storage) {
if (Array.isArray(error)) {
error = error[0];
}
storage.release();
ee.emit('error', {
uid: storage.uid,
name: storage.name,
branch: storage.branch,
error: error,
duration: process.hrtime(storage.startHr),
time: Date.now(),
});
},
};
}
module.exports = createExtensions;

7
node_modules/undertaker/lib/helpers/metadata.js generated vendored Normal file
View File

@ -0,0 +1,7 @@
'use strict';
// WeakMap for storing metadata
var WM = require('es6-weak-map');
var metadata = new WM();
module.exports = metadata;

52
node_modules/undertaker/lib/helpers/normalizeArgs.js generated vendored Normal file
View File

@ -0,0 +1,52 @@
'use strict';
var assert = require('assert');
var map = require('arr-map');
var flatten = require('arr-flatten');
var levenshtein = require('fast-levenshtein');
function normalizeArgs(registry, args) {
function getFunction(task) {
if (typeof task === 'function') {
return task;
}
var fn = registry.get(task);
if (!fn) {
var similar = similarTasks(registry, task);
if (similar.length > 0) {
assert(false, 'Task never defined: ' + task + ' - did you mean? ' + similar.join(', '));
} else {
assert(false, 'Task never defined: ' + task);
}
}
return fn;
}
var flattenArgs = flatten(args);
assert(flattenArgs.length, 'One or more tasks should be combined using series or parallel');
return map(flattenArgs, getFunction);
}
function similarTasks(registry, queryTask) {
if (typeof queryTask !== 'string') {
return [];
}
var tasks = registry.tasks();
var similarTasks = [];
for (var task in tasks) {
if (tasks.hasOwnProperty(task)) {
var distance = levenshtein.get(task, queryTask);
var allowedDistance = Math.floor(0.4 * task.length) + 1;
if (distance < allowedDistance) {
similarTasks.push(task);
}
}
}
return similarTasks;
}
module.exports = normalizeArgs;

View File

@ -0,0 +1,41 @@
'use strict';
var assert = require('assert');
function isFunction(fn) {
return typeof fn === 'function';
}
function isConstructor(registry) {
if (!(registry && registry.prototype)) {
return false;
}
var hasProtoGet = isFunction(registry.prototype.get);
var hasProtoSet = isFunction(registry.prototype.set);
var hasProtoInit = isFunction(registry.prototype.init);
var hasProtoTasks = isFunction(registry.prototype.tasks);
if (hasProtoGet || hasProtoSet || hasProtoInit || hasProtoTasks) {
return true;
}
return false;
}
function validateRegistry(registry) {
try {
assert(isFunction(registry.get), 'Custom registry must have `get` function');
assert(isFunction(registry.set), 'Custom registry must have `set` function');
assert(isFunction(registry.init), 'Custom registry must have `init` function');
assert(isFunction(registry.tasks), 'Custom registry must have `tasks` function');
} catch (err) {
if (isConstructor(registry)) {
assert(false, 'Custom registries must be instantiated, but it looks like you passed a constructor');
} else {
throw err;
}
}
}
module.exports = validateRegistry;

26
node_modules/undertaker/lib/last-run.js generated vendored Normal file
View File

@ -0,0 +1,26 @@
'use strict';
var retrieveLastRun = require('last-run');
var metadata = require('./helpers/metadata');
function lastRun(task, timeResolution) {
if (timeResolution == null) {
timeResolution = process.env.UNDERTAKER_TIME_RESOLUTION;
}
var fn = task;
if (typeof task === 'string') {
fn = this._getTask(task);
}
var meta = metadata.get(fn);
if (meta) {
fn = meta.orig || fn;
}
return retrieveLastRun(fn, timeResolution);
}
module.exports = lastRun;

31
node_modules/undertaker/lib/parallel.js generated vendored Normal file
View File

@ -0,0 +1,31 @@
'use strict';
var bach = require('bach');
var metadata = require('./helpers/metadata');
var buildTree = require('./helpers/buildTree');
var normalizeArgs = require('./helpers/normalizeArgs');
var createExtensions = require('./helpers/createExtensions');
function parallel() {
var create = this._settle ? bach.settleParallel : bach.parallel;
var args = normalizeArgs(this._registry, arguments);
var extensions = createExtensions(this);
var fn = create(args, extensions);
var name = '<parallel>';
metadata.set(fn, {
name: name,
branch: true,
tree: {
label: name,
type: 'function',
branch: true,
nodes: buildTree(args),
},
});
return fn;
}
module.exports = parallel;

25
node_modules/undertaker/lib/registry.js generated vendored Normal file
View File

@ -0,0 +1,25 @@
'use strict';
var reduce = require('object.reduce');
var validateRegistry = require('./helpers/validateRegistry');
function setTasks(inst, task, name) {
inst.set(name, task);
return inst;
}
function registry(newRegistry) {
if (!newRegistry) {
return this._registry;
}
validateRegistry(newRegistry);
var tasks = this._registry.tasks();
this._registry = reduce(tasks, setTasks, newRegistry);
this._registry.init(this);
}
module.exports = registry;

31
node_modules/undertaker/lib/series.js generated vendored Normal file
View File

@ -0,0 +1,31 @@
'use strict';
var bach = require('bach');
var metadata = require('./helpers/metadata');
var buildTree = require('./helpers/buildTree');
var normalizeArgs = require('./helpers/normalizeArgs');
var createExtensions = require('./helpers/createExtensions');
function series() {
var create = this._settle ? bach.settleSeries : bach.series;
var args = normalizeArgs(this._registry, arguments);
var extensions = createExtensions(this);
var fn = create(args, extensions);
var name = '<series>';
metadata.set(fn, {
name: name,
branch: true,
tree: {
label: name,
type: 'function',
branch: true,
nodes: buildTree(args),
},
});
return fn;
}
module.exports = series;

42
node_modules/undertaker/lib/set-task.js generated vendored Normal file
View File

@ -0,0 +1,42 @@
'use strict';
var assert = require('assert');
var metadata = require('./helpers/metadata');
function set(name, fn) {
assert(name, 'Task name must be specified');
assert(typeof name === 'string', 'Task name must be a string');
assert(typeof fn === 'function', 'Task function must be specified');
function taskWrapper() {
return fn.apply(this, arguments);
}
function unwrap() {
return fn;
}
taskWrapper.unwrap = unwrap;
taskWrapper.displayName = name;
var meta = metadata.get(fn) || {};
var nodes = [];
if (meta.branch) {
nodes.push(meta.tree);
}
var task = this._registry.set(name, taskWrapper) || taskWrapper;
metadata.set(task, {
name: name,
orig: fn,
tree: {
label: name,
type: 'task',
nodes: nodes,
},
});
}
module.exports = set;

16
node_modules/undertaker/lib/task.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
'use strict';
function task(name, fn) {
if (typeof name === 'function') {
fn = name;
name = fn.displayName || fn.name;
}
if (!fn) {
return this._getTask(name);
}
this._setTask(name, fn);
}
module.exports = task;

30
node_modules/undertaker/lib/tree.js generated vendored Normal file
View File

@ -0,0 +1,30 @@
'use strict';
var defaults = require('object.defaults');
var map = require('collection-map');
var metadata = require('./helpers/metadata');
function tree(opts) {
opts = defaults(opts || {}, {
deep: false,
});
var tasks = this._registry.tasks();
var nodes = map(tasks, function(task) {
var meta = metadata.get(task);
if (opts.deep) {
return meta.tree;
}
return meta.tree.label;
});
return {
label: 'Tasks',
nodes: nodes,
};
}
module.exports = tree;

View File

@ -0,0 +1,25 @@
(MIT License)
Copyright (c) 2013 [Ramesh Nair](http://www.hiddentao.com/)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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
NONINFRINGEMENT. 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.

View File

@ -0,0 +1,120 @@
# fast-levenshtein - Levenshtein algorithm in Javascript
[![Build Status](https://secure.travis-ci.org/hiddentao/fast-levenshtein.png)](http://travis-ci.org/hiddentao/fast-levenshtein)
An efficient Javascript implementation of the [Levenshtein algorithm](http://en.wikipedia.org/wiki/Levenshtein_distance) with asynchronous callback support.
## Features
* Works in node.js and in the browser.
* Better performance than other implementations by not needing to store the whole matrix ([more info](http://www.codeproject.com/Articles/13525/Fast-memory-efficient-Levenshtein-algorithm)).
* Provides synchronous and asynchronous versions of the algorithm.
* Asynchronous version is almost as fast as the synchronous version for small strings and can also provide progress updates.
* Comprehensive test suite and performance benchmark.
* Small: <1 KB minified and gzipped
## Installation
### node.js
Install using [npm](http://npmjs.org/):
```bash
$ npm install fast-levenshtein
```
### Browser
Using bower:
```bash
$ bower install fast-levenshtein
```
If you are not using any module loader system then the API will then be accessible via the `window.Levenshtein` object.
## Examples
**Synchronous**
```javascript
var levenshtein = require('fast-levenshtein');
var distance = levenshtein.get('back', 'book'); // 2
var distance = levenshtein.get('我愛你', '我叫你'); // 1
```
**Asynchronous**
```javascript
var levenshtein = require('fast-levenshtein');
levenshtein.getAsync('back', 'book', function (err, distance) {
// err is null unless an error was thrown
// distance equals 2
});
```
**Asynchronous with progress updates**
```javascript
var levenshtein = require('fast-levenshtein');
var hugeText1 = fs.readFileSync(...);
var hugeText2 = fs.readFileSync(...);
levenshtein.getAsync(hugeText1, hugeText2, function (err, distance) {
// process the results as normal
}, {
progress: function(percentComplete) {
console.log(percentComplete + ' % completed so far...');
}
);
```
## Building and Testing
To build the code and run the tests:
```bash
$ npm install -g grunt-cli
$ npm install
$ npm run build
```
## Performance
_Thanks to [Titus Wormer](https://github.com/wooorm) for [encouraging me](https://github.com/hiddentao/fast-levenshtein/issues/1) to do this._
Benchmarked against other node.js levenshtein distance modules (on Macbook Air 2012, Core i7, 8GB RAM):
```bash
Running suite Implementation comparison [benchmark/speed.js]...
>> levenshtein-edit-distance x 234 ops/sec ±3.02% (73 runs sampled)
>> levenshtein-component x 422 ops/sec ±4.38% (83 runs sampled)
>> levenshtein-deltas x 283 ops/sec ±3.83% (78 runs sampled)
>> natural x 255 ops/sec ±0.76% (88 runs sampled)
>> levenshtein x 180 ops/sec ±3.55% (86 runs sampled)
>> fast-levenshtein x 1,792 ops/sec ±2.72% (95 runs sampled)
Benchmark done.
Fastest test is fast-levenshtein at 4.2x faster than levenshtein-component
```
You can run this benchmark yourself by doing:
```bash
$ npm install -g grunt-cli
$ npm install
$ npm run build
$ npm run benchmark
```
## Contributing
If you wish to submit a pull request please update and/or create new tests for any changes you make and ensure the grunt build passes.
See [CONTRIBUTING.md](https://github.com/hiddentao/fast-levenshtein/blob/master/CONTRIBUTING.md) for details.
## License
MIT - see [LICENSE.md](https://github.com/hiddentao/fast-levenshtein/blob/master/LICENSE.md)

View File

@ -0,0 +1,211 @@
(function() {
'use strict';
/**
* Extend an Object with another Object's properties.
*
* The source objects are specified as additional arguments.
*
* @param dst Object the object to extend.
*
* @return Object the final object.
*/
var _extend = function(dst) {
var sources = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<sources.length; ++i) {
var src = sources[i];
for (var p in src) {
if (src.hasOwnProperty(p)) dst[p] = src[p];
}
}
return dst;
};
/**
* Defer execution of given function.
* @param {Function} func
*/
var _defer = function(func) {
if (typeof setImmediate === 'function') {
return setImmediate(func);
} else {
return setTimeout(func, 0);
}
};
/**
* Based on the algorithm at http://en.wikipedia.org/wiki/Levenshtein_distance.
*/
var Levenshtein = {
/**
* Calculate levenshtein distance of the two strings.
*
* @param str1 String the first string.
* @param str2 String the second string.
* @return Integer the levenshtein distance (0 and above).
*/
get: function(str1, str2) {
// base cases
if (str1 === str2) return 0;
if (str1.length === 0) return str2.length;
if (str2.length === 0) return str1.length;
// two rows
var prevRow = new Array(str2.length + 1),
curCol, nextCol, i, j, tmp;
// initialise previous row
for (i=0; i<prevRow.length; ++i) {
prevRow[i] = i;
}
// calculate current row distance from previous row
for (i=0; i<str1.length; ++i) {
nextCol = i + 1;
for (j=0; j<str2.length; ++j) {
curCol = nextCol;
// substution
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
// insertion
tmp = curCol + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// deletion
tmp = prevRow[j + 1] + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// copy current col value into previous (in preparation for next iteration)
prevRow[j] = curCol;
}
// copy last col value into previous (in preparation for next iteration)
prevRow[j] = nextCol;
}
return nextCol;
},
/**
* Asynchronously calculate levenshtein distance of the two strings.
*
* @param str1 String the first string.
* @param str2 String the second string.
* @param cb Function callback function with signature: function(Error err, int distance)
* @param [options] Object additional options.
* @param [options.progress] Function progress callback with signature: function(percentComplete)
*/
getAsync: function(str1, str2, cb, options) {
options = _extend({}, {
progress: null
}, options);
// base cases
if (str1 === str2) return cb(null, 0);
if (str1.length === 0) return cb(null, str2.length);
if (str2.length === 0) return cb(null, str1.length);
// two rows
var prevRow = new Array(str2.length + 1),
curCol, nextCol,
i, j, tmp,
startTime, currentTime;
// initialise previous row
for (i=0; i<prevRow.length; ++i) {
prevRow[i] = i;
}
nextCol = 1;
i = 0;
j = -1;
var __calculate = function() {
// reset timer
startTime = new Date().valueOf();
currentTime = startTime;
// keep going until one second has elapsed
while (currentTime - startTime < 1000) {
// reached end of current row?
if (str2.length <= (++j)) {
// copy current into previous (in preparation for next iteration)
prevRow[j] = nextCol;
// if already done all chars
if (str1.length <= (++i)) {
return cb(null, nextCol);
}
// else if we have more left to do
else {
nextCol = i + 1;
j = 0;
}
}
// calculation
curCol = nextCol;
// substution
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
// insertion
tmp = curCol + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// deletion
tmp = prevRow[j + 1] + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// copy current into previous (in preparation for next iteration)
prevRow[j] = curCol;
// get current time
currentTime = new Date().valueOf();
}
// send a progress update?
if (null !== options.progress) {
try {
options.progress.call(null, (i * 100.0/ str1.length));
} catch (err) {
return cb('Progress callback: ' + err.toString());
}
}
// next iteration
_defer(__calculate);
};
__calculate();
}
};
// amd
if (typeof define !== "undefined" && define !== null && define.amd) {
define(function() {
return Levenshtein;
});
}
// commonjs
else if (typeof module !== "undefined" && module !== null && typeof exports !== "undefined" && module.exports === exports) {
module.exports = Levenshtein;
}
// web worker
else if (typeof self !== "undefined" && typeof self.postMessage === 'function' && typeof self.importScripts === 'function') {
self.Levenshtein = Levenshtein;
}
// browser main thread
else if (typeof window !== "undefined" && window !== null) {
window.Levenshtein = Levenshtein;
}
}());

View File

@ -0,0 +1,37 @@
{
"name": "fast-levenshtein",
"version": "1.1.4",
"description": "Efficient implementation of Levenshtein algorithm with asynchronous callback support",
"main": "levenshtein.js",
"files": [
"levenshtein.js"
],
"scripts": {
"build": "grunt build",
"benchmark": "grunt benchmark",
"test": "mocha"
},
"devDependencies": {
"chai": "~1.5.0",
"grunt": "~0.4.1",
"grunt-benchmark": "~0.2.0",
"grunt-contrib-jshint": "~0.4.3",
"grunt-contrib-uglify": "~0.2.0",
"grunt-mocha-test": "~0.2.2",
"grunt-npm-install": "~0.1.0",
"load-grunt-tasks": "~0.6.0",
"lodash": "^4.0.1",
"mocha": "~1.9.0"
},
"repository": {
"type": "git",
"url": "https://github.com/hiddentao/fast-levenshtein.git"
},
"keywords": [
"levenshtein",
"distance",
"string"
],
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
"license": "MIT"
}

61
node_modules/undertaker/package.json generated vendored Normal file
View File

@ -0,0 +1,61 @@
{
"name": "undertaker",
"version": "1.3.0",
"description": "Task registry that allows composition through series/parallel methods.",
"author": "Gulp Team <team@gulpjs.com> (https://gulpjs.com/)",
"contributors": [
"Blaine Bublitz <blaine.bublitz@gmail.com>",
"Damien Lebrun <dinoboff@hotmail.com>"
],
"repository": "gulpjs/undertaker",
"license": "MIT",
"engines": {
"node": ">= 0.10"
},
"main": "index.js",
"files": [
"LICENSE",
"index.js",
"lib"
],
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "nyc mocha --async-only",
"azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"arr-flatten": "^1.0.1",
"arr-map": "^2.0.0",
"bach": "^1.0.0",
"collection-map": "^1.0.0",
"es6-weak-map": "^2.0.1",
"last-run": "^1.1.0",
"object.defaults": "^1.0.0",
"object.reduce": "^1.0.0",
"undertaker-registry": "^1.0.0",
"fast-levenshtein": "^1.0.0"
},
"devDependencies": {
"async-once": "^1.0.0",
"coveralls": "github:phated/node-coveralls#2.x",
"del": "^2.0.2",
"eslint": "^2.13.1",
"eslint-config-gulp": "^3.0.1",
"expect": "^1.20.2",
"gulp-jshint": "^1.8.4",
"mocha": "^3.0.0",
"nyc": "^10.3.2",
"once": "^1.3.1",
"through2": "^2.0.0",
"undertaker-common-tasks": "^1.0.0",
"undertaker-task-metadata": "^1.0.0",
"vinyl-fs": "^2.2.0"
},
"keywords": [
"registry",
"runner",
"task"
]
}