日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

inflect java_驼峰、下划线、单复数、表名-类名转换...通通交给字符串处理库:i...

發(fā)布時(shí)間:2024/3/13 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 inflect java_驼峰、下划线、单复数、表名-类名转换...通通交给字符串处理库:i... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

經(jīng)常會有字符串轉(zhuǎn)換處理的場景,比如一個(gè)實(shí)體user,對應(yīng)的Restful資源名是復(fù)數(shù)users,數(shù)據(jù)庫表名也是users,模型類名可能是User等等,這就需要一個(gè)方便的npm包,名字有點(diǎn)奇怪,不過它就是一個(gè)單字母:i

npm: https://www.npmjs.com/package/i

安裝

cnpm install i --save

使用

不一一列舉了,看名字就知道了

var inflect = require('i')();

var inflect = require('i')(true);

//如果是傳一個(gè)`true`的話就相當(dāng)于這些方法都加在了String.prototype上,所有的字符串都可以直接用這些方法。

//'messages to store'.titleize // === 'Messages To Store'

Pluralize

inflect.pluralize('person'); // === 'people'

inflect.pluralize('octopus'); // === 'octopi'

inflect.pluralize('Hat'); // === 'Hats'

Singularize

inflect.singularize('people'); // === 'person'

inflect.singularize('octopi'); // === 'octopus'

inflect.singularize('Hats'); // === 'Hat'

Camelize

inflect.camelize('message_properties'); // === 'MessageProperties'

inflect.camelize('message_properties', false); // === 'messageProperties'

Underscore

inflect.underscore('MessageProperties'); // === 'message_properties'

inflect.underscore('messageProperties'); // === 'message_properties'

Humanize

inflect.humanize('message_id'); // === 'Message'

Dasherize

inflect.dasherize('message_properties'); // === 'message-properties'

inflect.dasherize('Message Properties'); // === 'Message Properties'

Titleize

inflect.titleize('message_properties'); // === 'Message Properties'

inflect.titleize('message properties to keep'); // === 'Message Properties to Keep'

Demodulize

inflect.demodulize('Message.Bus.Properties'); // === 'Properties'

Tableize

inflect.tableize('MessageBusProperty'); // === 'message_bus_properties'

Classify

inflect.classify('message_bus_properties'); // === 'MessageBusProperty'

Foreign key

inflect.foreign_key('MessageBusProperty'); // === 'message_bus_property_id'

inflect.foreign_key('MessageBusProperty', false); // === 'message_bus_propertyid'

Ordinalize

inflect.ordinalize( '1' ); // === '1st'

自定義規(guī)則

Custom plural

可以使用正則表達(dá)式來定義

inflect.inflections.plural('person', 'guys');

inflect.pluralize('person'); // === 'guys'

inflect.singularize('guys'); // === 'guy'

Custom singular

inflect.inflections.singular('guys', 'person')

inflect.singularize('guys'); // === 'person'

inflect.pluralize('person'); // === 'people'

Custom irregular

inflect.inflections.irregular('person', 'guys')

inflect.pluralize('person'); // === 'guys'

inflect.singularize('guys'); // === 'person'

Custom human

inflect.inflections.human(/^(.*)_cnt$/i, '$1_count');

inflect.inflections.humanize('jargon_cnt'); // === 'Jargon count'

Custom uncountable

inflect.inflections.uncountable('oil')

inflect.pluralize('oil'); // === 'oil'

inflect.singularize('oil'); // === 'oil'

前后端通用哦...就這樣吧。

總結(jié)

以上是生活随笔為你收集整理的inflect java_驼峰、下划线、单复数、表名-类名转换...通通交给字符串处理库:i...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。