Skip to content

Commit 5755464

Browse files
Merge pull request #10 from tatarysh/master
fix: enhance length validation for different parameter types
2 parents 4d33fae + 01755d8 commit 5755464

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ node_modules/
22
.nyc_output
33
coverage
44
.vscode
5+
.idea
56
.npmrc
67
bench/node_modules/
78
dist/
8-
*.d.ts
9+
*.d.ts

defaultMethods.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@ const defaultMethods = {
153153
}
154154
return string.substr(from, end)
155155
},
156-
length: (i) => i.length,
156+
length: (i) => {
157+
if ((typeof i === 'string' || Array.isArray(i))) {
158+
return i.length
159+
}
160+
161+
if (i && typeof i === 'object') {
162+
return Object.keys(i).length
163+
}
164+
165+
return 0
166+
},
157167
get: {
158168
method: ([data, key, defaultValue], context, above, engine) => {
159169
const notFound = defaultValue === undefined ? null : defaultValue

0 commit comments

Comments
 (0)