1.4.6 • Published 11 months ago

naming-conventions-modeler v1.4.6

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Naming Conventions Modeler

npm Coverage npm GitHub Gitter documentation Build, Test and Publish

Simple and Fast TypeSafe naming conventions modeler implemented with Proxy; zero dependency.

Quick Start Guide

npm install --save naming-conventions-modeler
Originalsnake_casecamelCasePascalCasekebab-caseMACRO_CASETrain-Caseflatcaseno case
RegExrreg_exrregExrRegExrreg-exrREG_EXRReg-ExrregexrReg Exr
PCREpcrepcrePCREpcrePCREPCREpcrePCRE
JavaScriptjava_scriptjavaScriptJavaScriptjava-scriptJAVA_SCRIPTJava-ScriptjavascriptJava Script
JSProgrammingLanguagejs_programming_languagejsProgrammingLanguageJSProgrammingLanguagejs-programming-languageJS_PROGRAMMING_LANGUAGEJS-Programming-LanguagejsprogramminglanguageJS Programming Language
OTPotpotpOTPotpOTPOTPotpOTP
Train-Casetrain_casetrainCaseTrainCasetrain-caseTRAIN_CASETrain-CasetraincaseTrain Case
__meta__metametaMetametaMETAMetametameta
camelCasecamel_casecamelCaseCamelCasecamel-caseCAMEL_CASECamel-Casecamelcasecamel Case
_idididIdidIDIdidid
IDididIDidIDIDidID
iDididIDidIDIDidiD
idididIdidIDIdidid
IdididIdidIDIdidId
012301230123012301230123012301230123
_-$#@$#@$#@$#@$#@$#@$#@$#@$#@

Modeler

import { Modeler, lookup } from 'naming-conventions-modeler';

let obj = {
  _id: 123,
  TestValue: 'test value',
  data: {
    _id: 456,
    test_value: '456',
  },
  items: [
    {
      _id: 789,
      test_value: '789',
    },
  ],
  __meata__: 'metadata',
};

type camelObj = {
  // type safety support
  id: number;
  testValue: string;
  data: {
    id: number;
    testValue: string;
    [x: string]: any;
  };
  items: [
    {
      id: number;
      testValue: string;
    },
  ];
  meta: string;
  [x: string]: any;
};

// Replace misspell keys by regex
obj = lookup(obj, { '__me.*ta__': '__meta__' });

const model = Modeler.build<camelObj>(obj, 'camelCase');

console.log(model.id); // 123

console.log(model.testValue); // test value
console.log(model.TestValue); // test value

console.log(model.data.id); // 456
console.log(model.items[0].testValue); // 789

// Set value dynamically
model.NO_name = 'no name';
model.NO_VALUE = 'no value';

console.log(model.noName); // no name
console.log(model.noValue); // no value

/**
 * It takes an convention model and converts all properties at once
 */
Modeler.convert(model);

console.log(model);
/**
 * {
 *   data: { id: 456, testValue: '456' },
 *   items: [ { testValue: '789', id: 789 } ],
 *   testValue: 'test value',
 *   noName: 'no name',
 *   noValue: 'no value',
 *   id: 123,
 *   meta: 'metadata'
 * }
 */

Tools

import { convention, toSnakeCase, isSnakeCase } from 'naming-conventions-modeler';

const str = 'JSProgrammingLanguage';

const camelCase = convention('camelCase');

console.log(camelCase.to(str)); // jsProgrammingLanguage

console.log(toSnakeCase(str)); // js_programming_language

console.log(isSnakeCase(toSnakeCase(str))); // true

License

MIT

1.4.6

11 months ago

1.4.5

11 months ago

1.4.4

2 years ago

1.4.1

2 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.0.0

3 years ago