2 недели назад
История
README.md
Varname case detector/converter
Distribution
- is in file
dist/varname-case-js.js
; - contains object
VarnameCaseJs
that:- written in global namespace
window
; - contains same props than entry point;
- has same effects than entry point.
- written in global namespace
Entry point
Is in file lib/entry.js
and contains:
Property | Description |
---|---|
caseConverter converter |
Reexport of caseConverter |
caseDetector detector |
Reexport of caseDetector |
varnameCase facade |
Reexport of varnameCase |
Object{String} names |
Bind to casesRegistry.names |
casesRegistry registry |
Reexport of casesRegistry |
Also it has effect that allows to use some methods as functions of string primitives (extends String.prototype
).
Interfaces
Extendings of prototype
Prototype | Method | Description |
---|---|---|
String |
Boolean isCamelCase () |
Proxy to varnameCase.isCamelCase() |
String |
Boolean isCamelCaseLower () |
Proxy to varnameCase.isCamelCaseLower() |
String |
Boolean isCamelCaseUpper () |
Proxy to varnameCase.isCamelCaseUpper() |
String |
Boolean isKebabCase () |
Proxy to varnameCase.isKebabCase() |
String |
Boolean isKebabCaseLower () |
Proxy to varnameCase.isKebabCaseLower() |
String |
Boolean isKebabCaseUcfirst () |
Proxy to varnameCase.isKebabCaseUcfirst() |
String |
Boolean isKebabCaseUpper () |
Proxy to varnameCase.isKebabCaseUpper() |
String |
Boolean isSnakeCase () |
Proxy to varnameCase.isSnakeCase() |
String |
Boolean isSnakeCaseLower () |
Proxy to varnameCase.isSnakeCaseLower() |
String |
Boolean isSnakeCaseUcfirst () |
Proxy to varnameCase.isSnakeCaseUcfirst() |
String |
Boolean isSnakeCaseUpper () |
Proxy to varnameCase.isSnakeCaseUpper() |
String |
AbstractCase varnameCaseDetect () |
Proxy to varnameCase.detect() |
String |
String varnameCaseConvert (String caseName) |
Proxy to varnameCase.convert() |
Facade varnameCase
Constant/Method | Description |
---|---|
String CAMEL_CASE_LOWER |
Proxy to caseConverter.CAMEL_CASE_LOWER |
String CAMEL_CASE_UPPER |
Proxy to caseConverter.CAMEL_CASE_UPPER |
String KEBAB_CASE_LOWER |
Proxy to caseConverter.KEBAB_CASE_LOWER |
String KEBAB_CASE_UCFIRST |
Proxy to caseConverter.KEBAB_CASE_UCFIRST |
String KEBAB_CASE_UPPER |
Proxy to caseConverter.KEBAB_CASE_UPPER |
String SNAKE_CASE_LOWER |
Proxy to caseConverter.SNAKE_CASE_LOWER |
String SNAKE_CASE_UCFIRST |
Proxy to caseConverter.SNAKE_CASE_UCFIRST |
String SNAKE_CASE_UPPER |
Proxy to caseConverter.SNAKE_CASE_UPPER |
this register (AbstractCase caseProcessor) |
Proxy to casesRegistry.add() |
AbstractCase detect (String varname) |
Proxy to caseDetector.process() |
String convert (String varname, String caseName) |
Proxy to caseConverter.process() |
Boolean isCamelCase (String varname) |
Proxy to caseDetector.isCamelCase() |
Boolean isCamelCaseLower (String varname) |
Proxy to caseDetector.isCamelCaseLower() |
Boolean isCamelCaseUpper (String varname) |
Proxy to caseDetector.isCamelCaseUpper() |
Boolean isKebabCase (String varname) |
Proxy to caseDetector.isKebabCase() |
Boolean isKebabCaseLower (String varname) |
Proxy to caseDetector.isKebabCaseLower() |
Boolean isKebabCaseUcfirst (String varname) |
Proxy to caseDetector.isKebabCaseUcfirst() |
Boolean isKebabCaseUpper (String varname) |
Proxy to caseDetector.isKebabCaseUpper() |
Boolean isSnakeCase (String varname) |
Proxy to caseDetector.isSnakeCase() |
Boolean isSnakeCaseLower (String varname) |
Proxy to caseDetector.isSnakeCaseLower() |
Boolean isSnakeCaseUcfirst (String varname) |
Proxy to caseDetector.isSnakeCaseUcfirst() |
Boolean isSnakeCaseUpper (String varname) |
Proxy to caseDetector.isSnakeCaseUpper() |
Converter caseConverter
Constant/Method | Description |
---|---|
String CAMEL_CASE_LOWER |
Proxy to caseDetector.CAMEL_CASE_LOWER |
String CAMEL_CASE_UPPER |
Proxy to caseDetector.CAMEL_CASE_UPPER |
String KEBAB_CASE_LOWER |
Proxy to caseDetector.KEBAB_CASE_LOWER |
String KEBAB_CASE_UCFIRST |
Proxy to caseDetector.KEBAB_CASE_UCFIRST |
String KEBAB_CASE_UPPER |
Proxy to caseDetector.KEBAB_CASE_UPPER |
String SNAKE_CASE_LOWER |
Proxy to caseDetector.SNAKE_CASE_LOWER |
String SNAKE_CASE_UCFIRST |
Proxy to caseDetector.SNAKE_CASE_UCFIRST |
String SNAKE_CASE_UPPER |
Proxy to caseDetector.SNAKE_CASE_UPPER |
String process (String varname, String caseName) |
Returns varname in case caseName |
Detector caseDetector
Constant/Method | Description |
---|---|
String CAMEL_CASE_LOWER |
Proxy to casesRegistry.names.CAMEL_CASE_LOWER |
String CAMEL_CASE_UPPER |
Proxy to casesRegistry.names.CAMEL_CASE_UPPER |
String KEBAB_CASE_LOWER |
Proxy to casesRegistry.names.KEBAB_CASE_LOWER |
String KEBAB_CASE_UCFIRST |
Proxy to casesRegistry.names.KEBAB_CASE_UCFIRST |
String KEBAB_CASE_UPPER |
Proxy to casesRegistry.names.KEBAB_CASE_UPPER |
String SNAKE_CASE_LOWER |
Proxy to casesRegistry.names.SNAKE_CASE_LOWER |
String SNAKE_CASE_UCFIRST |
Proxy to casesRegistry.names.SNAKE_CASE_UCFIRST |
String SNAKE_CASE_UPPER |
Proxy to casesRegistry.names.SNAKE_CASE_UPPER |
AbstractCase process (String varname) |
Returns case instance for varname in case caseName |
Boolean isCamelCase (String varname) |
Checks is varname in some CamelCase |
Boolean isCamelCaseLower (String varname) |
Checks is varname in camelCaseLower |
Boolean isCamelCaseUpper (String varname) |
Checks is varname in CamelCaseUpper |
Boolean isKebabCase (String varname) |
Checks is varname in some Kebab-Case |
Boolean isKebabCaseLower (String varname) |
Checks is varname in kebab-case-lower |
Boolean isKebabCaseUcfirst (String varname) |
Checks is varname in Kebab-Case-Ucfirst |
Boolean isKebabCaseUpper (String varname) |
Checks is varname in KEBAB-CASE-UPPER |
Boolean isSnakeCase (String varname) |
Checks is varname in some Snake_Case |
Boolean isSnakeCaseLower (String varname) |
Checks is varname in snake_case_lower |
Boolean isSnakeCaseUcfirst (String varname) |
Checks is varname in Snake_Case_Ucfirst |
Boolean isSnakeCaseUpper (String varname) |
Checks is varname in SNAKE_CASE_UPPER |
Registry casesRegitry
Property/Method | Description |
---|---|
AbstractCase[] cases |
Contains array of known cases |
Number length |
Contains count of known cases |
Object{String} names |
Contains names of known cases |
this add (AbstractCase caseProcessor) |
Registers new case processor |
AbstractCase get (String caseName) |
Returns case processor by name |
Processors AbstractCase
Constant/Property/Method | Description |
---|---|
[static] String CASE_NAME |
Case name; should be in same case |
[static] RegExp REGEXP |
Regular expression to test varname |
[static] Function SPLITTER |
Function to split input varname into parts |
[static] Function PART_CONVERTER |
Function to convert parts of varname into this case |
[static] String PARTS_JOINER |
Separator to join parts of varname into whole string |
String|NULL varname |
Contains last tested varname |
Object|NULL testResult |
Contains result of last test (String.match() ) |
String[]|NULL nameParts |
Contains parts of last tested varname (String.split() ) |
self clone () |
Clones current object with last test |
Boolean test (String varname) |
Tests varname ; generates props varname /testResult /nameParts |
String[]|NULL parts (?String varname) |
Tests varname (or repeats it); returns nameParts |
Samples
Using global namespace
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="index.css" />
<title>@jzucen / Varname Case</title>
<script src="path/to/dist/varname-case-js.js"></script>
<script src="index.js"></script>
</head>
<body>
<noscript>
Your browser does not support JavaScript!
</noscript>
</body>
</html>
(addEventListener => {
addEventListener('load', () => {
(varnameCase => {
console.log(
// console output: ▶ KebabCaseLower {}
varnameCase.detect('some-var-name'),
// console output: 'anotherVarName'
varnameCase.convert('another_var_name', varnameCase.CAMEL_CASE_LOWER),
// console output: ▶ CamelCaseLower {}
'useProto'.varnameCaseDetect(),
// console output: 'USE_PROTO'
'UseProto'.varnameCaseConvert(varnameCase.SNAKE_CASE_UPPER)
);
})(window.VarnameCaseJs.facade);
});
})(window.addEventListener);
Using module import
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="index.css" />
<title>@jzucen / Varname Case</title>
<script src="index.js" type="module"></script>
</head>
<body>
<noscript>
Your browser does not support JavaScript!
</noscript>
</body>
</html>
import { facade as varnameCase } from 'path/to/lib/entry.js';
(addEventListener => {
addEventListener('load', () => {
console.log(
// console output: ▶ KebabCaseLower {}
varnameCase.detect('some-var-name'),
// console output: 'anotherVarName'
varnameCase.convert('another_var_name', varnameCase.CAMEL_CASE_LOWER),
// console output: ▶ CamelCaseLower {}
'useProto'.varnameCaseDetect(),
// console output: 'USE_PROTO'
'UseProto'.varnameCaseConvert(varnameCase.SNAKE_CASE_UPPER)
);
});
})(window.addEventListener);
Built-in sample
# build, up docker and go to its console
make vm-build
make vm-up
make vm-console
# build dependencies and start http-server
make server
# open in browser received url; hit Ctrl+C to stop server
# exit and stop docker
exit
make vm-down
Описание
Varname case detector/converter
Конвейеры
0 успешных
0 с ошибкой