Skip to content

Commit

Permalink
remove usage of lodash _.isString.
Browse files Browse the repository at this point in the history
relates to #68
  • Loading branch information
Shahar Soel committed Jan 5, 2016
1 parent 4b1852b commit 2124402
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/parse/parser_public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ namespace chevrotain {
lookAheadFunc:LookAheadFunc | GrammarAction,
action:GrammarAction | string,
errMsg?:string):void {
if (_.isString(action)) {
if (utils.isString(action)) {
errMsg = <any>action
action = <any>lookAheadFunc
lookAheadFunc = this.getLookaheadFuncForAtLeastOne(prodOccurrence)
Expand Down Expand Up @@ -1357,7 +1357,7 @@ namespace chevrotain {

let separatorsResult = []

if (_.isString(action)) {
if (utils.isString(action)) {
errMsg = <any>action
action = <any>firstIterationLookAheadFunc
firstIterationLookAheadFunc = this.getLookaheadFuncForAtLeastOneSep(prodOccurrence)
Expand Down
6 changes: 3 additions & 3 deletions src/scan/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace chevrotain {
if (groupName === Lexer.SKIPPED) {
return undefined
}
else if (_.isString(groupName)) {
else if (utils.isString(groupName)) {
return groupName
}
else if (_.isUndefined(groupName)) {
Expand All @@ -63,7 +63,7 @@ namespace chevrotain {

let emptyGroups = _.reduce(onlyRelevantClasses, (acc, clazz:any) => {
let groupName = clazz.GROUP
if (_.isString(groupName)) {
if (utils.isString(groupName)) {
acc[groupName] = []
}
return acc
Expand Down Expand Up @@ -221,7 +221,7 @@ namespace chevrotain {
let group = clazz.GROUP

return group !== Lexer.SKIPPED &&
group !== Lexer.NA && !_.isString(group)
group !== Lexer.NA && !utils.isString(group)
})

let errors = utils.map(invalidTypes, (currClass) => {
Expand Down
2 changes: 1 addition & 1 deletion src/scan/tokens_public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace chevrotain {
// used to support js inheritance patterns that do not use named functions
// in that situation setting a property tokenName on a token constructor will
// enable producing readable error messages.
if (_.isString((<any>clazz).tokenName)) {
if (utils.isString((<any>clazz).tokenName)) {
return (<any>clazz).tokenName
}
else {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ namespace chevrotain.utils {
}
}
}

export function isString(item:any):boolean {
return typeof item === "string"
}
}
8 changes: 8 additions & 0 deletions test/utils/utils_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ namespace chevrotain.utils.spec {
throw Error("call back should not be invoked for empty array")
})
})

it("exports a isString utility", () => {
expect(isString("")).to.be.true
expect(isString("bamba")).to.be.true
expect(isString(66)).to.be.false
expect(isString(null)).to.be.false
})

})
}

0 comments on commit 2124402

Please sign in to comment.