Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fs-p

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-p

fs-extra on Promises. Typescript-friendly

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
846
increased by4.96%
Maintainers
1
Weekly downloads
 
Created
Source

DEPRECATED

fs-extra has a promise-based API as of v4.0.0. TypeScript-friendly.

fs-p

fs-p is a TypeScript-friendly promise-based wrapper on top of fs-extra package.

Why?

Previously, there was no TypeScript-friendly promise-based fs-extra implementation. Now there is.

Installation

npm install --save fs-p or yarn add fs-p

Usage

fs-p api is no different from fs-extra, except, async methods are wrapped in Promises. Check out the original fs-extra documentation.

Promise-based async

Most methods are async and return Promises, unlike the original fs-extra callback-based implementaion.

Sync methods, on the other hand, will throw if an error occurs.

fs-p vs fs-extra

Methods with no return value example:

import * as fs from 'fs-extra'
import * as fsp from 'fs-p'

// fs-extra callback style
fs.copy('/tmp/myfile', '/tmp/mynewfile', (err: Error) => {
  if (err) return console.error(err)
  console.log("success!")
}) // copies file

// fs-p promise-based
fsp.copy('/tmp/mydir', '/tmp/mynewdir').then(
  () => console.log('success!')
).catch((err) => console.error(err))

// fs-p async/await
try {
  await fsp.copy('/tmp/mydir', '/tmp/mynewdir')
  console.log('success!')
} catch (err) { console.error(err) }

Methods with a return value:

import * as fs from 'fs-extra'
import * as fsp from 'fs-p'

// fs-extra callback style
fs.readJson('./package.json', (err: Error, packageObj: any) => {
  console.log(packageObj.version) // => 0.1.3
})

// fs-p promise-based
fsp.readJson('./package.json').then(
  (packageObj: any) => console.log(packageObj.version) // => 0.1.3
).catch((err) => console.error(err))

// fs-p async/await
try {
  const packageObj: any = await fsp.readJson('./package.json')
  console.log(packageObj.version) // => 0.1.3
} catch (err) { console.error(err) }

Credits

fs-p is just a small wrapper over a remarkable fs-extra package. Thus, all the credit goes to fs-extra authors

License

Copyright 2017 Grammarly, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Package last updated on 06 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc