mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(write-file-encoding): add support for encoding option (#44800)
* feat(write-file-encoding): add support for encoding option The api supports string as an option This string option is the encodign of the data, defaulting to 'utf8'. As the Node types are referenced, simply BufferEncoding is beign used instead of string or string aliases to align with Node types. For backward compatiblity options 'encoding' is defined as: BufferEncoding | '' https://github.com/npm/write-file-atomic#write-file-atomic Thanks! * Be specific about allowed encoding as per PR comment /cc @amcasey
This commit is contained in:
parent
bce8dab379
commit
99fe2e5223
12
types/write-file-atomic/index.d.ts
vendored
12
types/write-file-atomic/index.d.ts
vendored
@ -2,25 +2,29 @@
|
||||
// Project: https://github.com/npm/write-file-atomic
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Jay Rylan <https://github.com/jayrylan>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export = writeFile;
|
||||
|
||||
declare function writeFile(filename: string, data: string | Buffer, options: writeFile.Options, callback: (error?: Error) => void): void;
|
||||
declare function writeFile(filename: string, data: string | Buffer, options: writeFile.Options | BufferEncoding, callback: (error?: Error) => void): void;
|
||||
declare function writeFile(filename: string, data: string | Buffer, callback: (error?: Error) => void): void;
|
||||
declare function writeFile(filename: string, data: string | Buffer, options?: writeFile.Options): Promise<void>;
|
||||
declare function writeFile(filename: string, data: string | Buffer, options?: writeFile.Options | BufferEncoding): Promise<void>;
|
||||
|
||||
declare namespace writeFile {
|
||||
function sync(filename: string, data: string | Buffer, options?: Options): void;
|
||||
function sync(filename: string, data: string | Buffer, options?: Options | BufferEncoding): void;
|
||||
|
||||
interface Options {
|
||||
chown?: {
|
||||
uid: number;
|
||||
gid: number;
|
||||
};
|
||||
encoding?: string;
|
||||
/**
|
||||
* @default 'utf8'
|
||||
*/
|
||||
encoding?: BufferEncoding;
|
||||
fsync?: boolean;
|
||||
mode?: number;
|
||||
}
|
||||
|
||||
@ -3,16 +3,17 @@ import writeFileAtomic = require('write-file-atomic');
|
||||
writeFileAtomic('message.txt', 'Hello Node', err => {});
|
||||
|
||||
writeFileAtomic('message.txt', 'Hello Node', {chown: {uid: 100, gid: 50}}, err => {});
|
||||
writeFileAtomic('message.txt', 'Hello Node', {encoding: ''}, err => {});
|
||||
writeFileAtomic('message.txt', 'Hello Node', {fsync: false}, err => {});
|
||||
writeFileAtomic('message.txt', 'Hello Node', {mode: 123}, err => {});
|
||||
writeFileAtomic('message.txt', 'Hello Node', 'utf8', err => {});
|
||||
|
||||
writeFileAtomic('message.txt', 'Hello Node').then(() => {}).catch(() => {});
|
||||
writeFileAtomic('message.txt', 'Hello Node', {mode: 123}).then(() => {}).catch(() => {});
|
||||
writeFileAtomic('message.txt', 'Hello Node', 'utf8').then(() => {}).catch(() => {});
|
||||
|
||||
writeFileAtomic.sync('message.txt', 'Hello Node');
|
||||
|
||||
writeFileAtomic.sync('message.txt', 'Hello Node', {chown: {uid: 100, gid: 50}});
|
||||
writeFileAtomic.sync('message.txt', 'Hello Node', {encoding: ''});
|
||||
writeFileAtomic.sync('message.txt', 'Hello Node', {fsync: false});
|
||||
writeFileAtomic.sync('message.txt', 'Hello Node', {mode: 123});
|
||||
writeFileAtomic.sync('message.txt', 'Hello Node', 'utf8');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user