Skip to content

Commit c37cdc1

Browse files
committed
Initialize
0 parents  commit c37cdc1

10 files changed

+390
-0
lines changed

.gitignore

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Created by https://www.gitignore.io/api/node,webstorm
2+
# Edit at https://www.gitignore.io/?templates=node,webstorm
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# TypeScript v1 declaration files
49+
typings/
50+
51+
# TypeScript cache
52+
*.tsbuildinfo
53+
54+
# Optional npm cache directory
55+
.npm
56+
57+
# Optional eslint cache
58+
.eslintcache
59+
60+
# Optional REPL history
61+
.node_repl_history
62+
63+
# Output of 'npm pack'
64+
*.tgz
65+
66+
# Yarn Integrity file
67+
.yarn-integrity
68+
69+
# dotenv environment variables file
70+
.env
71+
.env.test
72+
73+
# parcel-bundler cache (https://parceljs.org/)
74+
.cache
75+
76+
# next.js build output
77+
.next
78+
79+
# nuxt.js build output
80+
.nuxt
81+
82+
# react / gatsby
83+
public/
84+
85+
# vuepress build output
86+
.vuepress/dist
87+
88+
# Serverless directories
89+
.serverless/
90+
91+
# FuseBox cache
92+
.fusebox/
93+
94+
# DynamoDB Local files
95+
.dynamodb/
96+
97+
### WebStorm ###
98+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
99+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
100+
101+
# User-specific stuff
102+
.idea/**/workspace.xml
103+
.idea/**/tasks.xml
104+
.idea/**/usage.statistics.xml
105+
.idea/**/dictionaries
106+
.idea/**/shelf
107+
108+
# Generated files
109+
.idea/**/contentModel.xml
110+
111+
# Sensitive or high-churn files
112+
.idea/**/dataSources/
113+
.idea/**/dataSources.ids
114+
.idea/**/dataSources.local.xml
115+
.idea/**/sqlDataSources.xml
116+
.idea/**/dynamic.xml
117+
.idea/**/uiDesigner.xml
118+
.idea/**/dbnavigator.xml
119+
120+
# Gradle
121+
.idea/**/gradle.xml
122+
.idea/**/libraries
123+
124+
# Gradle and Maven with auto-import
125+
# When using Gradle or Maven with auto-import, you should exclude module files,
126+
# since they will be recreated, and may cause churn. Uncomment if using
127+
# auto-import.
128+
# .idea/modules.xml
129+
# .idea/*.iml
130+
# .idea/modules
131+
# *.iml
132+
# *.ipr
133+
134+
# CMake
135+
cmake-build-*/
136+
137+
# Mongo Explorer plugin
138+
.idea/**/mongoSettings.xml
139+
140+
# File-based project format
141+
*.iws
142+
143+
# IntelliJ
144+
out/
145+
146+
# mpeltonen/sbt-idea plugin
147+
.idea_modules/
148+
149+
# JIRA plugin
150+
atlassian-ide-plugin.xml
151+
152+
# Cursive Clojure plugin
153+
.idea/replstate.xml
154+
155+
# Crashlytics plugin (for Android Studio and IntelliJ)
156+
com_crashlytics_export_strings.xml
157+
crashlytics.properties
158+
crashlytics-build.properties
159+
fabric.properties
160+
161+
# Editor-based Rest Client
162+
.idea/httpRequests
163+
164+
# Android studio 3.1+ serialized cache file
165+
.idea/caches/build_file_checksums.ser
166+
167+
### WebStorm Patch ###
168+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
169+
170+
# *.iml
171+
# modules.xml
172+
# .idea/misc.xml
173+
# *.ipr
174+
175+
# Sonarlint plugin
176+
.idea/**/sonarlint/
177+
178+
# SonarQube Plugin
179+
.idea/**/sonarIssues.xml
180+
181+
# Markdown Navigator plugin
182+
.idea/**/markdown-navigator.xml
183+
.idea/**/markdown-navigator/
184+
185+
# End of https://www.gitignore.io/api/node,webstorm

.idea/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/similarity-string.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var similarity = function (s1, s2) {
4+
var longer = s1;
5+
var shorter = s2;
6+
if (s1.length < s2.length) {
7+
longer = s2;
8+
shorter = s1;
9+
}
10+
var longerLength = longer.length;
11+
if (longerLength === 0) {
12+
return 1.0;
13+
}
14+
return (longerLength - distance(longer, shorter)) / parseFloat(longerLength.toString());
15+
};
16+
var similarityPercent = function (s1, s2) {
17+
return Math.round(similarity(s1, s2) * 10000) / 100;
18+
};
19+
exports.similarityPercent = similarityPercent;
20+
var distance = function (s1, s2) {
21+
s1 = s1.toLowerCase();
22+
s2 = s2.toLowerCase();
23+
var costs = [];
24+
for (var i = 0; i <= s1.length; i++) {
25+
var lastValue = i;
26+
for (var j = 0; j <= s2.length; j++) {
27+
if (i == 0) {
28+
costs[j] = j;
29+
}
30+
else {
31+
if (j > 0) {
32+
var newValue = costs[j - 1];
33+
if (s1.charAt(i - 1) != s2.charAt(j - 1)) {
34+
newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1;
35+
}
36+
costs[j - 1] = lastValue;
37+
lastValue = newValue;
38+
}
39+
}
40+
}
41+
if (i > 0) {
42+
costs[s2.length] = lastValue;
43+
}
44+
}
45+
return costs[s2.length];
46+
};

index.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const similarity = (s1: string, s2: string): number => {
2+
let longer = s1;
3+
let shorter = s2;
4+
5+
if (s1.length < s2.length) {
6+
longer = s2;
7+
shorter = s1;
8+
}
9+
10+
const longerLength = longer.length;
11+
12+
if (longerLength === 0) {
13+
return 1.0;
14+
}
15+
16+
return (longerLength - distance(longer, shorter)) / parseFloat(longerLength.toString());
17+
};
18+
19+
const similarityPercent = (s1: string, s2: string): number => {
20+
return Math.round(similarity(s1, s2) * 10000)/100;
21+
};
22+
23+
const distance = (s1: string, s2: string) => {
24+
s1 = s1.toLowerCase();
25+
s2 = s2.toLowerCase();
26+
const costs = [];
27+
for (let i = 0; i <= s1.length; i++) {
28+
let lastValue = i;
29+
for (let j = 0; j <= s2.length; j++) {
30+
if (i == 0) {
31+
costs[j] = j;
32+
} else {
33+
if (j > 0) {
34+
let newValue = costs[j - 1];
35+
if (s1.charAt(i - 1) != s2.charAt(j - 1)) {
36+
newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1;
37+
}
38+
costs[j - 1] = lastValue;
39+
lastValue = newValue;
40+
}
41+
}
42+
}
43+
if (i > 0) {
44+
costs[s2.length] = lastValue;
45+
}
46+
}
47+
return costs[s2.length];
48+
};
49+
50+
51+
export {similarityPercent};

package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "similarity-string",
3+
"version": "1.0.0",
4+
"description": "A library implementing different string similarity and distance measures using Javascript.",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "[email protected]",
10+
"license": "ISC"
11+
}

0 commit comments

Comments
 (0)