Initial import with skill sheet working

This commit is contained in:
2024-12-04 00:11:23 +01:00
commit 9050c80ab4
4488 changed files with 671048 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, 2016-2020, 2022 Blaine Bublitz <blaine.bublitz@gmail.com> and Eric Schoffstall <yo@contra.io>.
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.

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

@ -0,0 +1,319 @@
<p align="center">
<a href="https://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] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
Task registry that allows composition through series/parallel methods.
## 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.
Assuming `undertakerInst.lastRun('someTask')` returns `1426000001111`,
`undertakerInst.lastRun('someTask', 1000)` returns `1426000001000`.
The default time resolution is `1`.
## 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
<!-- prettier-ignore-start -->
[downloads-image]: https://img.shields.io/npm/dm/undertaker.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/undertaker
[npm-image]: https://img.shields.io/npm/v/undertaker.svg?style=flat-square
[ci-url]: https://github.com/gulpjs/undertaker/actions?query=workflow:dev
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/undertaker/dev?style=flat-square
[coveralls-url]: https://coveralls.io/r/gulpjs/undertaker
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/undertaker/master.svg?style=flat-square
<!-- prettier-ignore-end -->
<!-- prettier-ignore-start -->
[async-resolution]: https://github.com/phated/async-done#completion-and-error-resolution
[undertaker-registry]: https://github.com/gulpjs/undertaker-registry
[custom-registries]: #custom-registries
[archy]: https://www.npmjs.org/package/archy
[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
<!-- prettier-ignore-end -->

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;

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

@ -0,0 +1,27 @@
'use strict';
var metadata = require('./metadata');
function buildTree(tasks) {
return Object.values(tasks).map(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;

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

@ -0,0 +1,5 @@
'use strict';
var metadata = new WeakMap();
module.exports = metadata;

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

@ -0,0 +1,55 @@
'use strict';
var assert = require('assert');
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);
var err;
if (similar.length > 0) {
err = new Error('Task never defined: ' + task + ' - did you mean? ' + similar.join(', '));
err.task = task;
err.similar = similar;
} else {
err = new Error('Task never defined: ' + task);
err.task = task;
}
throw err;
}
return fn;
}
var flattenArgs = Array.prototype.concat.apply([], args);
assert(flattenArgs.length, 'One or more tasks should be combined using series or parallel');
return flattenArgs.map(getFunction);
}
function similarTasks(registry, queryTask) {
if (typeof queryTask !== 'string') {
return [];
}
var tasks = registry.tasks();
var similarTasks = [];
for (var task in tasks) {
if (Object.prototype.hasOwnProperty.call(tasks, 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;

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

@ -0,0 +1,22 @@
'use strict';
var retrieveLastRun = require('last-run');
var metadata = require('./helpers/metadata');
function lastRun(task, timeResolution) {
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 validateRegistry = require('./helpers/validateRegistry');
function setTasks(registry, nameAndTask) {
var name = nameAndTask[0];
var task = nameAndTask[1];
registry.set(name, task);
return registry;
}
function registry(newRegistry) {
if (!newRegistry) {
return this._registry;
}
validateRegistry(newRegistry);
var tasks = this._registry.tasks();
this._registry = Object.entries(tasks).reduce(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;

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

@ -0,0 +1,25 @@
'use strict';
var metadata = require('./helpers/metadata');
function tree(opts) {
opts = Object.assign({ deep: false }, opts);
var tasks = this._registry.tasks();
var nodes = Object.values(tasks).map(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,69 @@
# fast-levenshtein - Levenshtein algorithm in Javascript
[![Build Status](https://secure.travis-ci.org/hiddentao/fast-levenshtein.png)](http://travis-ci.org/hiddentao/fast-levenshtein)
[![NPM module](https://badge.fury.io/js/fast-levenshtein.png)](https://badge.fury.io/js/fast-levenshtein)
[![NPM downloads](https://img.shields.io/npm/dm/fast-levenshtein.svg?maxAge=2592000)](https://www.npmjs.com/package/fast-levenshtein)
[![Follow on Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/hiddentao)
A Javascript implementation of the [Levenshtein algorithm](http://en.wikipedia.org/wiki/Levenshtein_distance) with locale-specific collator support. This uses [fastest-levenshtein](https://github.com/ka-weihe/fastest-levenshtein) under the hood.
## Features
* Works in node.js and in the browser.
* Locale-sensitive string comparisons if needed.
* Comprehensive test suite.
## Installation
```bash
$ npm install fast-levenshtein
```
**CDN**
The latest version is now also always available at https://npm-cdn.com/pkg/fast-levenshtein/
## Examples
**Default usage**
```javascript
var levenshtein = require('fast-levenshtein');
var distance = levenshtein.get('back', 'book'); // 2
var distance = levenshtein.get('我愛你', '我叫你'); // 1
```
**Locale-sensitive string comparisons**
It supports using [Intl.Collator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator) for locale-sensitive string comparisons:
```javascript
var levenshtein = require('fast-levenshtein');
levenshtein.get('mikailovitch', 'Mikhaïlovitch', { useCollator: true});
// 1
```
## Building and Testing
To build the code and run the tests:
```bash
$ npm install -g grunt-cli
$ npm install
$ npm run build
```
## Performance
This uses [fastest-levenshtein](https://github.com/ka-weihe/fastest-levenshtein) under the hood.
## 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,107 @@
(function() {
'use strict';
var collator;
try {
collator = (typeof Intl !== "undefined" && typeof Intl.Collator !== "undefined") ? Intl.Collator("generic", { sensitivity: "base" }) : null;
} catch (err){
console.log("Collator could not be initialized and wouldn't be used");
}
var levenshtein = require('fastest-levenshtein');
// arrays to re-use
var prevRow = [],
str2Char = [];
/**
* 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.
* @param [options] Additional options.
* @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
* @return Integer the levenshtein distance (0 and above).
*/
get: function(str1, str2, options) {
var useCollator = (options && collator && options.useCollator);
if (useCollator) {
var str1Len = str1.length,
str2Len = str2.length;
// base cases
if (str1Len === 0) return str2Len;
if (str2Len === 0) return str1Len;
// two rows
var curCol, nextCol, i, j, tmp;
// initialise previous row
for (i=0; i<str2Len; ++i) {
prevRow[i] = i;
str2Char[i] = str2.charCodeAt(i);
}
prevRow[str2Len] = str2Len;
var strCmp;
// calculate current row distance from previous row using collator
for (i = 0; i < str1Len; ++i) {
nextCol = i + 1;
for (j = 0; j < str2Len; ++j) {
curCol = nextCol;
// substution
strCmp = 0 === collator.compare(str1.charAt(i), String.fromCharCode(str2Char[j]));
nextCol = prevRow[j] + (strCmp ? 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;
}
return levenshtein.distance(str1, str2);
}
};
// 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,42 @@
{
"name": "fast-levenshtein",
"version": "3.0.0",
"description": "Efficient implementation of Levenshtein algorithm with locale-specific collator support.",
"main": "levenshtein.js",
"files": [
"levenshtein.js"
],
"scripts": {
"build": "grunt build",
"prepublish": "npm run build",
"benchmark": "grunt benchmark",
"test": "mocha"
},
"devDependencies": {
"chai": "~1.5.0",
"grunt": "~0.4.1",
"grunt-benchmark": "~0.2.0",
"grunt-cli": "^1.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",
"dependencies": {
"fastest-levenshtein": "^1.0.7"
}
}

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

@ -0,0 +1,61 @@
{
"name": "undertaker",
"version": "2.0.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": ">=10.13.0"
},
"main": "index.js",
"files": [
"LICENSE",
"index.js",
"lib"
],
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "nyc mocha --async-only"
},
"dependencies": {
"bach": "^2.0.1",
"fast-levenshtein": "^3.0.0",
"last-run": "^2.0.0",
"undertaker-registry": "^2.0.0"
},
"devDependencies": {
"async-once": "^2.0.0",
"del": "^6.1.1",
"eslint": "^7.32.0",
"eslint-config-gulp": "^5.0.1",
"eslint-plugin-node": "^11.1.0",
"expect": "^27.5.1",
"mocha": "^8.4.0",
"nyc": "^15.1.0",
"once": "^1.4.0",
"through2": "^4.0.2",
"undertaker-common-tasks": "^2.0.0",
"undertaker-task-metadata": "^2.0.0",
"vinyl-fs": "^4.0.0"
},
"nyc": {
"reporter": [
"lcov",
"text-summary"
]
},
"prettier": {
"singleQuote": true
},
"keywords": [
"registry",
"runner",
"task"
]
}