Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

textlint-rule-ja-hiragana-fukushi

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

textlint-rule-ja-hiragana-fukushi - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

22

lib/index.js

@@ -5,7 +5,7 @@ "use strict";

var fs = require('fs');
var fs = require("fs");
var kuromojin = require("kuromojin");
var createMatcher = require("morpheme-match-all");
var yaml = require('js-yaml');
var data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", 'utf8'));
var yaml = require("js-yaml");
var data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", "utf8"));

@@ -20,4 +20,4 @@ var dictionaries = [];

dictionaries.push({
message: data.message + ": \"" + form + "\" > \"" + item.fix_form + "\"",
fix: item.fix_form,
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"",
fix: item.expected,
tokens: item.tokens

@@ -42,8 +42,3 @@ });

var results = matchAll(actualTokens);
/*
console.log("/-----------------------");
console.log(actualTokens);
console.log(results);
console.log("-----------------------/");
*/
if (results.length == 0) {

@@ -65,5 +60,2 @@ return;

});
//console.log(node);
//console.log("-----------------------");
//console.log(result);
report(node, ruleError);

@@ -73,3 +65,3 @@ });

});
};
}

@@ -76,0 +68,0 @@ function getIndexFromTokens(tokenIndex, actualTokens) {

{
"version": "1.0.2",
"version": "1.0.3",
"keywords": [

@@ -18,2 +18,3 @@ "textlintrule"

"devDependencies": {
"eslint": "^3.17.1",
"textlint-scripts": "^1.2.2"

@@ -20,0 +21,0 @@ },

"use strict";
const fs = require('fs');
const fs = require("fs");
const kuromojin = require("kuromojin");
const createMatcher = require("morpheme-match-all");
const yaml = require('js-yaml');
const data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", 'utf8'));
const yaml = require("js-yaml");
const data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", "utf8"));
let dictionaries = [];
const dictionaries = [];

@@ -17,4 +17,4 @@ data.dict.forEach(function (item) {

dictionaries.push({
message: data.message + ": \"" + form + "\" > \"" + item.fix_form + "\"",
fix: item.fix_form,
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"",
fix: item.expected,
tokens: item.tokens

@@ -27,39 +27,31 @@ });

function reporter(context, options = {}) {
const {Syntax, RuleError, report, getSource, fixer} = context;
return {
[Syntax.Str](node){ // "Str" node
const text = getSource(node); // Get text
return kuromojin(text).then((actualTokens) => {
const results = matchAll(actualTokens);
/*
console.log("/-----------------------");
console.log(actualTokens);
console.log(results);
console.log("-----------------------/");
*/
if (results.length == 0) {
return;
}
const {Syntax, RuleError, report, getSource, fixer} = context;
return {
[Syntax.Str](node){ // "Str" node
const text = getSource(node); // Get text
return kuromojin(text).then((actualTokens) => {
const results = matchAll(actualTokens);
results.forEach(function (result) {
let tokenIndex = result.index;
let index = getIndexFromTokens(tokenIndex, actualTokens);
let replaceFrom = "";
result.tokens.forEach(function(token){
replaceFrom += token.surface_form;
});
let replaceTo = fixer.replaceTextRange([index, index + replaceFrom.length], result.dict.fix);
let ruleError = new RuleError(result.dict.message, {
index: index,
fix: replaceTo // https://github.com/textlint/textlint/blob/master/docs/rule-fixable.md
});
//console.log(node);
//console.log("-----------------------");
//console.log(result);
report(node, ruleError);
if (results.length == 0) {
return;
}
results.forEach(function (result) {
const tokenIndex = result.index;
const index = getIndexFromTokens(tokenIndex, actualTokens);
let replaceFrom = "";
result.tokens.forEach(function(token){
replaceFrom += token.surface_form;
});
const replaceTo = fixer.replaceTextRange([index, index + replaceFrom.length], result.dict.fix);
const ruleError = new RuleError(result.dict.message, {
index: index,
fix: replaceTo // https://github.com/textlint/textlint/blob/master/docs/rule-fixable.md
});
report(node, ruleError);
});
}
});
}
};
};
}

@@ -66,0 +58,0 @@ function getIndexFromTokens(tokenIndex, actualTokens) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc