Node - Update mappings API
@@ -176,32 +176,26 @@ declare_types! {
Ok(js_overflowings.upcast())
}
- method wordBoundaries(mut cx) {
- // wordBoundaries(index: number): [number, number]
+ method charToToken(mut cx) {
+ // charToToken(pos: number): number | undefined
- let index = cx.argument::<JsNumber>(0)?.value() as usize;
+ let pos = cx.argument::<JsNumber>(0)?.value() as usize;
let this = cx.this();
let guard = cx.lock();
-
- let res = this.borrow(&guard).encoding.execute(|encoding| {
- encoding.unwrap().word_boundaries(index)
+ let index = this.borrow(&guard).encoding.execute(|encoding| {
+ encoding.unwrap().char_to_token(pos)
});
- if let Some(boundaries) = res {
- let js_tuple = JsArray::new(&mut cx, 2);
- let n = cx.number(boundaries.0 as f64);
- js_tuple.set(&mut cx, 0, n)?;
- let n = cx.number(boundaries.1 as f64);
- js_tuple.set(&mut cx, 1, n)?;
- Ok(js_tuple.upcast())
+ if let Some(index) = index {
+ Ok(cx.number(index as f64).upcast())
} else {
Ok(cx.undefined().upcast())
}
}
- method charToWord(mut cx) {
- // charToWord(pos: number): [number, number]
+ method charToWordOffsets(mut cx) {
+ // charToWordOffsets(pos: number): [number, number] | undefined
let pos = cx.argument::<JsNumber>(0)?.value() as usize;
@@ -209,7 +203,7 @@ declare_types! {
let guard = cx.lock();
let res = this.borrow(&guard).encoding.execute(|encoding| {
- encoding.unwrap().char_to_word(pos)
+ encoding.unwrap().char_to_word_offsets(pos)
});
if let Some(offsets) = res {
@@ -224,8 +218,8 @@ declare_types! {
}
}
- method charToToken(mut cx) {
- // charToToken(pos: number): [number, number]
+ method charToTokenOffsets(mut cx) {
+ // charToTokenOffsets(pos: number): [number, number] | undefined
let pos = cx.argument::<JsNumber>(0)?.value() as usize;
@@ -233,7 +227,7 @@ declare_types! {
let guard = cx.lock();
let res = this.borrow(&guard).encoding.execute(|encoding| {
- encoding.unwrap().char_to_token(pos)
+ encoding.unwrap().char_to_token_offsets(pos)
});
if let Some(offsets) = res {
@@ -248,8 +242,8 @@ declare_types! {
}
}
- method tokenToWord(mut cx) {
- // tokenToWord(index: number): [number, number]
+ method tokenToWordOffsets(mut cx) {
+ // tokenToWordOffsets(index: number): [number, number] | undefined
let index = cx.argument::<JsNumber>(0)?.value() as usize;
@@ -257,7 +251,7 @@ declare_types! {
let guard = cx.lock();
let res = this.borrow(&guard).encoding.execute(|encoding| {
- encoding.unwrap().token_to_word(index)
+ encoding.unwrap().token_to_word_offsets(index)
});
if let Some(offsets) = res {
