fix(napi): re-export JsDate as Date in prelude
This commit is contained in:
parent
5002e782a4
commit
80ea0ad78c
8 changed files with 20 additions and 0 deletions
|
@ -169,6 +169,7 @@ static KNOWN_TYPES: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
|||
("BigUint64Array", "BigUint64Array"),
|
||||
("DataView", "DataView"),
|
||||
("Date", "Date"),
|
||||
("JsDate", "Date"),
|
||||
("JsBuffer", "Buffer"),
|
||||
("Buffer", "Buffer"),
|
||||
("Vec", "Array<{}>"),
|
||||
|
|
|
@ -23,6 +23,8 @@ mod string;
|
|||
mod symbol;
|
||||
mod task;
|
||||
|
||||
#[cfg(feature = "napi5")]
|
||||
pub use crate::JsDate as Date;
|
||||
pub use array::*;
|
||||
pub use arraybuffer::*;
|
||||
#[cfg(feature = "napi6")]
|
||||
|
|
|
@ -40,6 +40,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
/** napi = { version = 2, features = ["serde-json"] } */␊
|
||||
export function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void␊
|
||||
export function returnJsFunction(): (...args: any[]) => any␊
|
||||
export function dateToNumber(input: Date): number␊
|
||||
export function eitherStringOrNumber(input: string | number): number␊
|
||||
export function returnEither(input: number): string | number␊
|
||||
export function either3(input: string | number | boolean): number␊
|
||||
|
|
Binary file not shown.
|
@ -82,6 +82,7 @@ import {
|
|||
returnJsFunction,
|
||||
testSerdeRoundtrip,
|
||||
createObjWithProperty,
|
||||
dateToNumber,
|
||||
} from '../'
|
||||
|
||||
test('export const', (t) => {
|
||||
|
@ -548,3 +549,10 @@ Napi4Test('Promise should reject raw error in rust', async (t) => {
|
|||
const err = await t.throwsAsync(() => asyncPlus100(Promise.reject(fxError)))
|
||||
t.is(err, fxError)
|
||||
})
|
||||
|
||||
const Napi5Test = Number(process.versions.napi) >= 5 ? test : test.skip
|
||||
|
||||
Napi5Test('Date test', (t) => {
|
||||
const fixture = new Date('2016-12-24')
|
||||
t.is(dateToNumber(fixture), fixture.valueOf())
|
||||
})
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -30,6 +30,7 @@ export function optionOnly(callback: (arg0?: string | undefined | null) => void)
|
|||
/** napi = { version = 2, features = ["serde-json"] } */
|
||||
export function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void
|
||||
export function returnJsFunction(): (...args: any[]) => any
|
||||
export function dateToNumber(input: Date): number
|
||||
export function eitherStringOrNumber(input: string | number): number
|
||||
export function returnEither(input: number): string | number
|
||||
export function either3(input: string | number | boolean): number
|
||||
|
|
6
examples/napi/src/date.rs
Normal file
6
examples/napi/src/date.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use napi::bindgen_prelude::*;
|
||||
|
||||
#[napi]
|
||||
fn date_to_number(input: Date) -> Result<f64> {
|
||||
input.value_of()
|
||||
}
|
|
@ -18,6 +18,7 @@ mod bigint;
|
|||
mod callback;
|
||||
mod class;
|
||||
mod class_factory;
|
||||
mod date;
|
||||
mod either;
|
||||
mod r#enum;
|
||||
mod error;
|
||||
|
|
Loading…
Reference in a new issue