
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
fs-p
is a TypeScript-friendly promise-based wrapper on top of fs-extra package.
Previously, there was no TypeScript-friendly promise-based fs-extra
implementation. Now there is.
npm install --save fs-p
or yarn add fs-p
fs-p
api is no different from fs-extra
, except, async methods are wrapped in Promises.
Check out the original fs-extra
documentation.
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) }
fs-p
is just a small wrapper over a remarkable fs-extra
package. Thus, all the credit goes to fs-extra
authors
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.
FAQs
fs-extra on Promises. Typescript-friendly
The npm package fs-p receives a total of 200 weekly downloads. As such, fs-p popularity was classified as not popular.
We found that fs-p demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.