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.1.0 to 1.2.0

53

lib/index.js

@@ -9,22 +9,38 @@ "use strict";

var yaml = require("js-yaml");
var data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", "utf8"));
var dictionaries = [];
var path = require("path");
var untildify = require("untildify");
data.dict.forEach(function (item) {
var form = "";
item.tokens.forEach(function (token) {
form += token.surface_form;
var defaultOptions = {
rulePath: __dirname + "/../dict/fukushi.yml"
};
function loadDictionaries(rulePath, baseDir) {
if (typeof rulePath === "undefined" || rulePath === "") {
return null;
}
var expandedRulePath = untildify(rulePath);
var dictionaries = [];
var data = yaml.safeLoad(fs.readFileSync(path.resolve(baseDir, expandedRulePath), "utf8"));
data.dict.forEach(function (item) {
var form = "";
item.tokens.forEach(function (token) {
form += token.surface_form;
});
dictionaries.push({
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"",
fix: item.expected,
tokens: item.tokens
});
});
dictionaries.push({
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"",
fix: item.expected,
tokens: item.tokens
});
});
var matchAll = createMatcher(dictionaries);
return dictionaries;
}
function reporter(context) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var userOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = Object.assign(defaultOptions, userOptions);
var matchAll = createMatcher(loadDictionaries(options.rulePath, getConfigBaseDir(context)));
var Syntax = context.Syntax,

@@ -72,2 +88,11 @@ RuleError = context.RuleError,

// from https://github.com/textlint-rule/textlint-rule-prh/blob/master/src/textlint-rule-prh.js#L147
var getConfigBaseDir = function getConfigBaseDir(context) {
if (typeof context.getConfigBaseDir === "function") {
return context.getConfigBaseDir() || process.cwd();
}
var textlintRcFilePath = context.config ? context.config.configFile : null;
return textlintRcFilePath ? path.dirname(textlintRcFilePath) : process.cwd();
};
module.exports = {

@@ -74,0 +99,0 @@ linter: reporter,

{
"version": "1.1.0",
"version": "1.2.0",
"keywords": [

@@ -35,4 +35,5 @@ "textlintrule"

"kuromojin": "^1.3.2",
"morpheme-match-all": "^1.1.0"
"morpheme-match-all": "^1.1.0",
"untildify": "^4.0.0"
}
}

@@ -25,2 +25,14 @@ # textlint-rule-ja-hiragana-fukushi

Or you can specify custom dictionary as follows:
```json
{
"rules": {
"ja-hiragana-fukushi": {
"rulePath": "path/to/fukushi.yml"
}
}
}
```
Via CLI

@@ -27,0 +39,0 @@

@@ -7,21 +7,36 @@ "use strict";

const yaml = require("js-yaml");
const data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", "utf8"));
const dictionaries = [];
const path = require("path");
const untildify = require("untildify");
data.dict.forEach(function (item) {
var form = "";
item.tokens.forEach(function (token) {
form += token.surface_form;
const defaultOptions = {
rulePath: __dirname + "/../dict/fukushi.yml"
};
function loadDictionaries(rulePath, baseDir) {
if (typeof rulePath === "undefined" || rulePath ==="") {
return null;
}
const expandedRulePath = untildify(rulePath);
const dictionaries = [];
const data = yaml.safeLoad(fs.readFileSync(path.resolve(baseDir, expandedRulePath), "utf8"));
data.dict.forEach(function (item) {
var form = "";
item.tokens.forEach(function (token) {
form += token.surface_form;
});
dictionaries.push({
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"",
fix: item.expected,
tokens: item.tokens
});
});
dictionaries.push({
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"",
fix: item.expected,
tokens: item.tokens
});
});
const matchAll = createMatcher(dictionaries);
return dictionaries;
}
function reporter(context, options = {}) {
function reporter(context, userOptions = {}) {
const options = Object.assign(defaultOptions, userOptions);
const matchAll = createMatcher(loadDictionaries(options.rulePath, getConfigBaseDir(context)));
const {Syntax, RuleError, report, getSource, fixer} = context;

@@ -65,2 +80,11 @@ return {

// from https://github.com/textlint-rule/textlint-rule-prh/blob/master/src/textlint-rule-prh.js#L147
const getConfigBaseDir = context => {
if (typeof context.getConfigBaseDir === "function") {
return context.getConfigBaseDir() || process.cwd();
}
const textlintRcFilePath = context.config ? context.config.configFile : null;
return textlintRcFilePath ? path.dirname(textlintRcFilePath) : process.cwd();
};
module.exports = {

@@ -67,0 +91,0 @@ linter: reporter,

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