File tree Expand file tree Collapse file tree 5 files changed +330
-1822
lines changed Expand file tree Collapse file tree 5 files changed +330
-1822
lines changed Original file line number Diff line number Diff line change 11import { resolve , join } from 'path'
2- import merge from 'lodash.merge'
32
43module . exports = function nuxtVueApiQueriesModule ( moduleOptions = { } ) {
54 const { apiQueries = { } } = this . options
6- const options = merge ( { } , moduleOptions , apiQueries )
5+ const options = Object . assign ( { } , moduleOptions , apiQueries )
76 this . addPlugin ( {
87 src : resolve ( __dirname , './templates/plugin.js' ) ,
98 fileName : join ( 'vue-api-queries.js' ) ,
Original file line number Diff line number Diff line change 1313 "build" : " yarn clean && tsc" ,
1414 "watch" : " tsc -w" ,
1515 "start" : " yarn link && nodemon" ,
16- "semantic- release" : " semantic-release " ,
16+ "release" : " standard-version && git push --follow-tags origin main && yarn publish " ,
1717 "prepublish" : " yarn test && yarn build" ,
1818 "clean" : " rimraf dist" ,
1919 "prepare" : " husky install"
6565 "nuxt" : " ^2.15.8" ,
6666 "prettier" : " ^2.4.1" ,
6767 "rimraf" : " ^3.0.2" ,
68- "semantic-release " : " ^18.0.0 " ,
68+ "standard-version " : " ^9.3.1 " ,
6969 "ts-jest" : " ^27.0.5" ,
7070 "typescript" : " ^4.4.3"
7171 },
Original file line number Diff line number Diff line change @@ -189,4 +189,28 @@ describe('Validator', () => {
189189
190190 expect ( validator . any ( [ 'first_name' , 'last_name' ] , false ) ) . toBeTruthy ( )
191191 } )
192+
193+ it ( 'get first by field' , ( ) => {
194+ const errors = {
195+ first_name : [ 'This first name field is required' ] ,
196+ last_name : [ 'This last name field is required' ] ,
197+ age : [ 'This age field is required' ] ,
198+ }
199+
200+ expect ( validator . firstBy ( errors , 'age' ) ) . toEqual (
201+ 'This age field is required' ,
202+ )
203+ } )
204+
205+ it ( 'get first by without any field' , ( ) => {
206+ const errors = {
207+ first_name : [ 'This fist name field is required' ] ,
208+ last_name : [ 'This last name field is required' ] ,
209+ age : [ 'This age field is required' ] ,
210+ }
211+
212+ expect ( validator . firstBy ( errors ) ) . toEqual (
213+ 'This fist name field is required' ,
214+ )
215+ } )
192216} )
Original file line number Diff line number Diff line change @@ -46,6 +46,19 @@ class Validator {
4646 return this . get ( field ) [ 0 ]
4747 }
4848
49+ firstBy ( obj : Record < string , any > , field = '' ) {
50+ let value
51+ if ( ! field ) {
52+ value = obj [ Object . keys ( obj ) [ 0 ] ]
53+ } else {
54+ value = obj [ field ]
55+ }
56+ if ( isArray ( value ) ) {
57+ return value [ 0 ]
58+ }
59+ return value
60+ }
61+
4962 missed ( field ?: string | string [ ] ) : boolean {
5063 return ! this . has ( field )
5164 }
You can’t perform that action at this time.
0 commit comments