lib6/mapping.nameconventions.js
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export var StandardCase;
(function (StandardCase) {
StandardCase["SnakeCase"] = "snake_case";
StandardCase["KebabCase"] = "kebab-case";
StandardCase["ScreamingSnakeCase"] = "SCREAMING_SNAKE_CASE";
StandardCase["PascalCase"] = "PascalCase";
StandardCase["CamelCase"] = "camelCase";
})(StandardCase || (StandardCase = {}));
export const nameConventions = {
snake_case: {
tokenize: (name) => name.split('_'),
encode: (tokens) => tokens.join('_')
},
'kebab-case': {
tokenize: (name) => name.split('-'),
encode: (tokens) => tokens.join('-')
},
PascalCase: {
tokenize: (name) => name.split(/(?=[A-Z])/).map((token) => token.toLowerCase()),
encode: (tokens) => {
let name = '';
for (let token of tokens) {
token = token.charAt(0).toUpperCase() + token.slice(1);
name += token;
}
return name;
}
},
camelCase: {
tokenize: (name) => name.split(/(?=[A-Z])/).map((token) => token.toLowerCase()),
encode: (tokens) => {
let name = '';
for (let [i, token] of tokens.entries()) {
if (i !== 0) {
token = token.charAt(0).toUpperCase() + token.slice(1);
}
name += token;
}
return name;
}
},
SCREAMING_SNAKE_CASE: {
tokenize: (name) => name.split('_').map((token) => token.toLowerCase()),
encode: (tokens) => tokens.join('_').toUpperCase()
}
};