From 38490156c391168c2e44b18b31bbbfe7c63a7962 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Sun, 28 Feb 2016 17:05:36 +0100 Subject: [PATCH] Add definitions for inflected library --- inflected/inflected-tests.ts | 48 ++++++++++++++++++++++++++++++++++++ inflected/inflected.d.ts | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 inflected/inflected-tests.ts create mode 100644 inflected/inflected.d.ts diff --git a/inflected/inflected-tests.ts b/inflected/inflected-tests.ts new file mode 100644 index 000000000..05a54a5d0 --- /dev/null +++ b/inflected/inflected-tests.ts @@ -0,0 +1,48 @@ +/// + +import * as Inflector from "inflected"; + +Inflector.pluralize("Category"); +Inflector.singularize("Categories"); +Inflector.camelize("nerd_bar", false); +Inflector.underscore('FooBar') // => 'foo_bar' +//Inflector.humanize('employee_salary') // => 'Employee salary' +//Inflector.humanize('author_id') // => 'Author' +Inflector.humanize('author_id', { capitalize: false }) // => 'author' + +Inflector.titleize('man from the boondocks') // => 'Man From The Boondocks' +Inflector.titleize('x-men: the last stand') // => 'X Men: The Last Stand' +Inflector.titleize('TheManWithoutAPast') // => 'The Man Without A Past' +Inflector.titleize('raiders_of_the_lost_ark') // => 'Raiders Of The Lost Ark' + +Inflector.tableize('RawScaledScorer') // => 'raw_scaled_scorers' +Inflector.tableize('egg_and_ham') // => 'egg_and_hams' +Inflector.tableize('fancyCategory') // => 'fancy_categories' + +Inflector.classify('egg_and_hams') // => 'EggAndHam' +Inflector.classify('posts') // => 'Post' + +Inflector.dasherize('puni_puni') // => 'puni-puni' + +Inflector.foreignKey('Message') // => 'message_id' +Inflector.foreignKey('Message', false) // => 'messageid' + +Inflector.ordinal(1) // => 'st' +Inflector.ordinal(2) // => 'nd' +Inflector.ordinal(1002) // => 'nd' +Inflector.ordinal(1003) // => 'rd' +Inflector.ordinal(-11) // => 'th' +Inflector.ordinal(-1021) // => 'st' + +Inflector.ordinalize(1) // => '1st' +Inflector.ordinalize(2) // => '2nd' +Inflector.ordinalize(1002) // => '1002nd' +Inflector.ordinalize(1003) // => '1003rd' +Inflector.ordinalize(-11) // => '-11th' +Inflector.ordinalize(-1021) // => '-1021st' + +Inflector.transliterate('Ærøskøbing') // => 'AEroskobing' + +Inflector.parameterize('Donald E. Knuth') // => 'donald-e-knuth' +Inflector.parameterize('Donald E. Knuth', { separator: '+' }) // => 'donald+e+knuth' + diff --git a/inflected/inflected.d.ts b/inflected/inflected.d.ts new file mode 100644 index 000000000..49a72ef3c --- /dev/null +++ b/inflected/inflected.d.ts @@ -0,0 +1,44 @@ +// Type definitions for inflected 1.1.6 +// Project: https://github.com/martinandert/inflected +// Definitions by: Daniel Schmidt +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "inflected" { + + module Options { + interface Humanize { + capitalize: boolean; + } + + interface Transliterate { + locale: string; + replacement: string; + } + + interface Parameterize { + separator: string; + } + } + + interface Inflected { + pluralize(word: string, locale?: string): string; + singularize(word: string, locale?: string): string; + camelize(term: string, uppercaseFirstLetter?: boolean): string; + underscore(camelCaseWord: string): string; + humanize(lowerCaseAndUnderscoredWord: string, + options?: Options.Humanize): string; + titleize(sentence: string): string; + tableize(className: string): string; + classify(tableName: string): string; + dasherize(underscoredWord: string): string; + foreignKey(className: string, + separateClassNameAndIdWithUnderscore?:boolean): string; + ordinal(number: number): string; + ordinalize(number: number): string; + transliterate(sentence: string, options?: Options.Transliterate): string; + parameterize(sentence: string, options?: Options.Parameterize): string; + } + + var Inflector:Inflected; + export = Inflector; +} \ No newline at end of file