Skip to content

Commit

Permalink
fix #1113 toNumbers return vals
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Jun 10, 2024
1 parent 1a252e1 commit 329f52b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import nlp from './src/three.js'
// nlp.plugin(plg)
// nlp.verbose('tagger')

const text_1 = 'There are twenty-four apples and 12000 oranges on the table.'
const text_1 = '90 hertz'
const doc = nlp(text_1)

doc.values(0).toNumber().debug()
doc.values().toNumber().debug()

// let doc = nlp(` `).debug()

Expand Down
12 changes: 7 additions & 5 deletions src/3-three/numbers/numbers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@ const addMethod = function (View) {

/** convert to numeric form like '8' or '8th' */
toNumber() {
let m = this.if('#TextValue')
m.forEach(val => {
let res = this.map(val => {
if (!this.has('#TextValue')) {
return val
}
let obj = parse(val)
if (obj.num === null) {
return
return val
}
let fmt = val.has('#Ordinal') ? 'Ordinal' : 'Cardinal'
let str = format(obj, fmt)
val.replaceWith(str, { tags: true })
val.tag('NumericValue')
return val.tag('NumericValue')
})
return this
return new Numbers(res.document, res.pointer)
}
/** add commas, or nicer formatting for numbers */
toLocaleString() {
Expand Down

0 comments on commit 329f52b

Please sign in to comment.