graphile-simple-inflector 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +15 -6
- package/index.js +15 -6
- package/package.json +6 -5
package/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { pluralize, singularize, fixCapitalisedPlural } from 'inflekt';
|
|
2
|
+
const fixCapitalisedPluralWrapper = (fn) => function capitalisedPlural(str) {
|
|
2
3
|
const original = fn.call(this, str);
|
|
3
|
-
return original
|
|
4
|
+
return fixCapitalisedPlural(original);
|
|
4
5
|
};
|
|
5
6
|
const fixChangePlural = (fn) => function changePlural(str) {
|
|
6
7
|
const matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
|
|
@@ -12,6 +13,9 @@ const fixChangePlural = (fn) => function changePlural(str) {
|
|
|
12
13
|
const suffix = str.slice(suffixIndex);
|
|
13
14
|
return `${prefix}${fn.call(this, word)}${suffix}`;
|
|
14
15
|
};
|
|
16
|
+
// Helper functions that use inflekt library directly (no 'this' dependency)
|
|
17
|
+
const inflektPluralize = (str) => pluralize(str);
|
|
18
|
+
const inflektSingularize = (str) => singularize(str);
|
|
15
19
|
const DEFAULT_NODE_ID = 'nodeId';
|
|
16
20
|
export const PgSimpleInflector = (builder, { pgSimpleCollections, pgOmitListSuffix, pgSimplifyPatch = true, pgSimplifyAllRows = true, pgShortPk = true, pgSimplifyMultikeyRelations = true, pgSimplifyOppositeBaseNames = true, nodeIdFieldName = DEFAULT_NODE_ID, } = {}) => {
|
|
17
21
|
const hasConnections = pgSimpleCollections !== 'only';
|
|
@@ -34,14 +38,19 @@ export const PgSimpleInflector = (builder, { pgSimpleCollections, pgOmitListSuff
|
|
|
34
38
|
* This solves the issue with `blah-table1s` becoming `blahTable1S`
|
|
35
39
|
* (i.e. the capital S at the end) or `table1-connection becoming `Table1SConnection`
|
|
36
40
|
*/
|
|
37
|
-
camelCase:
|
|
38
|
-
upperCamelCase:
|
|
41
|
+
camelCase: fixCapitalisedPluralWrapper(oldInflection.camelCase),
|
|
42
|
+
upperCamelCase: fixCapitalisedPluralWrapper(oldInflection.upperCamelCase),
|
|
39
43
|
/*
|
|
40
44
|
* Pluralize/singularize only supports single words, so only run
|
|
41
45
|
* on the final segment of a name.
|
|
46
|
+
* Use inflekt library instead of the default pluralize library.
|
|
42
47
|
*/
|
|
43
|
-
pluralize: fixChangePlural(
|
|
44
|
-
|
|
48
|
+
pluralize: fixChangePlural(function pluralize(str) {
|
|
49
|
+
return inflektPluralize(str);
|
|
50
|
+
}),
|
|
51
|
+
singularize: fixChangePlural(function singularize(str) {
|
|
52
|
+
return inflektSingularize(str);
|
|
53
|
+
}),
|
|
45
54
|
distinctPluralize(str) {
|
|
46
55
|
const singular = this.singularize(str);
|
|
47
56
|
const plural = this.pluralize(singular);
|
package/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PgSimpleInflector = void 0;
|
|
4
|
-
const
|
|
4
|
+
const inflekt_1 = require("inflekt");
|
|
5
|
+
const fixCapitalisedPluralWrapper = (fn) => function capitalisedPlural(str) {
|
|
5
6
|
const original = fn.call(this, str);
|
|
6
|
-
return
|
|
7
|
+
return (0, inflekt_1.fixCapitalisedPlural)(original);
|
|
7
8
|
};
|
|
8
9
|
const fixChangePlural = (fn) => function changePlural(str) {
|
|
9
10
|
const matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
|
|
@@ -15,6 +16,9 @@ const fixChangePlural = (fn) => function changePlural(str) {
|
|
|
15
16
|
const suffix = str.slice(suffixIndex);
|
|
16
17
|
return `${prefix}${fn.call(this, word)}${suffix}`;
|
|
17
18
|
};
|
|
19
|
+
// Helper functions that use inflekt library directly (no 'this' dependency)
|
|
20
|
+
const inflektPluralize = (str) => (0, inflekt_1.pluralize)(str);
|
|
21
|
+
const inflektSingularize = (str) => (0, inflekt_1.singularize)(str);
|
|
18
22
|
const DEFAULT_NODE_ID = 'nodeId';
|
|
19
23
|
const PgSimpleInflector = (builder, { pgSimpleCollections, pgOmitListSuffix, pgSimplifyPatch = true, pgSimplifyAllRows = true, pgShortPk = true, pgSimplifyMultikeyRelations = true, pgSimplifyOppositeBaseNames = true, nodeIdFieldName = DEFAULT_NODE_ID, } = {}) => {
|
|
20
24
|
const hasConnections = pgSimpleCollections !== 'only';
|
|
@@ -37,14 +41,19 @@ const PgSimpleInflector = (builder, { pgSimpleCollections, pgOmitListSuffix, pgS
|
|
|
37
41
|
* This solves the issue with `blah-table1s` becoming `blahTable1S`
|
|
38
42
|
* (i.e. the capital S at the end) or `table1-connection becoming `Table1SConnection`
|
|
39
43
|
*/
|
|
40
|
-
camelCase:
|
|
41
|
-
upperCamelCase:
|
|
44
|
+
camelCase: fixCapitalisedPluralWrapper(oldInflection.camelCase),
|
|
45
|
+
upperCamelCase: fixCapitalisedPluralWrapper(oldInflection.upperCamelCase),
|
|
42
46
|
/*
|
|
43
47
|
* Pluralize/singularize only supports single words, so only run
|
|
44
48
|
* on the final segment of a name.
|
|
49
|
+
* Use inflekt library instead of the default pluralize library.
|
|
45
50
|
*/
|
|
46
|
-
pluralize: fixChangePlural(
|
|
47
|
-
|
|
51
|
+
pluralize: fixChangePlural(function pluralize(str) {
|
|
52
|
+
return inflektPluralize(str);
|
|
53
|
+
}),
|
|
54
|
+
singularize: fixChangePlural(function singularize(str) {
|
|
55
|
+
return inflektSingularize(str);
|
|
56
|
+
}),
|
|
48
57
|
distinctPluralize(str) {
|
|
49
58
|
const singular = this.singularize(str);
|
|
50
59
|
const plural = this.pluralize(singular);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-simple-inflector",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Simple inflector plugin for Graphile/PostGraphile",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/constructive",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"url": "https://github.com/constructive-io/constructive/issues"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"graphile-test": "^2.13.
|
|
43
|
+
"graphile-test": "^2.13.3",
|
|
44
44
|
"graphql-tag": "2.12.6",
|
|
45
45
|
"makage": "^0.1.10",
|
|
46
|
-
"pgsql-test": "^2.24.
|
|
46
|
+
"pgsql-test": "^2.24.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"graphile-build": "^4.14.1"
|
|
49
|
+
"graphile-build": "^4.14.1",
|
|
50
|
+
"inflekt": "^0.1.2"
|
|
50
51
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "22c89cfc6f67879e77ca47f652c31c80828665f5"
|
|
52
53
|
}
|