Gathering detailed insights and metrics for fetch-normalize-data
Gathering detailed insights and metrics for fetch-normalize-data
Gathering detailed insights and metrics for fetch-normalize-data
Gathering detailed insights and metrics for fetch-normalize-data
react-api-data
Fetch and normalize data from api
react-api-data-cross-fetch
Fetch and normalize data from api
with-react-redux-login
React hoc component for rendering page only on user sign success. It uses fetch-normalize-data as implicit helper.
redux-thunk-data
A lib for fetching normalized data in a redux store through thunks.
A library to obtain a state of normalized data. Special fetch and reducer helpers are also provided in the export.
npm install fetch-normalize-data
Typescript
Module System
67.4
Supply Chain
99
Quality
82.3
Maintenance
100
Vulnerability
80.6
License
JavaScript (99.35%)
Shell (0.65%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MPL-2.0 License
7 Stars
326 Commits
1 Forks
8 Watchers
18 Branches
18 Contributors
Updated on Dec 17, 2021
Minified
Minified + Gzipped
Latest Version
1.22.7
Package Id
fetch-normalize-data@1.22.7
Unpacked Size
144.00 kB
Size
26.03 kB
File Count
67
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A library to obtain a state of normalized data. Special fetch and reducer helpers are also provided in the export.
An implementation with a redux-thunk context is here, there for redux-saga. You can see also a poc with only a React Context (redux free) at this. Also, see this post for a presentation based on the pass culture project.
If you want to merge patched data into an already existing state:
1import { getNormalizedMergedState } from 'fetch-normalize-data' 2 3const state = { 4 authors: [{ id: 0, name: "John Marxou" }], 5 books: [{ authorId: 0, id: 0, text: "my foo" }] 6} 7 8const patch = { 9 books: [ 10 { 11 author: { id: 1, name: "Edmond Frostan" }, 12 id: 1, 13 text: "you foo" 14 } 15 ] 16} 17 18const config = { 19 normalizer: { 20 books: { 21 normalizer: { 22 // short syntax here: <datumKey>: <stateKey> 23 author: "authors" 24 }, 25 stateKey: "books" 26 } 27 } 28} 29 30const nextState = getNormalizedMergedState(state, patch, config) 31 32console.log(nextState)
We have:
1{ 2 authors: [ 3 { id: 0, name: "John Marxou" }, 4 { id: 1, name: "Edmond Frostan" } 5 ], 6 books: [ 7 { authorId: 0, id: 0, text: "my foo" }, 8 { 9 authorId: 1, 10 id: 1, 11 text: "you foo" 12 } 13 ] 14}
import { getNormalizedDeletedState } from 'fetch-normalize-data'
1const state = { 2 authors: [{ id: 0, name: "John Marxou" }], 3 books: [{ authorId: 0, id: 0, text: "my foo" }] 4} 5 6const patch = { 7 books: [{ id: 1 }] 8} 9 10const nextState = getNormalizedDeletedState(state, patch, config) 11 12console.log(nextState)
We have:
1{ 2 authors: [ 3 { id: 0, name: "John Marxou" } 4 ], 5 books: [] 6}
config of getNormalizedMergedState can have:
name | type | example | isRequired | default | description |
---|---|---|---|---|---|
isMergingArray | bool | See test | non | true | decide if nextState. |
isMergingDatum | bool | See test | non | false | decide if nextState.<arrayName>[...<datum>] will be a merge from previous and next datum or just a replace with next datum |
isMutatingArray | bool | See test | non | true | decide if nextState. |
isMutatingDatum | bool | See test | non | false | decide if nextState.<arrayName>[...<datum>] will be a clone or a merge into the previous datum |
normalizer | objet | See test | non | null | a nested object giving relationships between datumKeys and entities to be store at stateKeys |
name | type | example | isRequired | default | description |
---|---|---|---|---|---|
apiPath | string | /foos | no | undefined | apiPath will be join with rootUrl to build the request url |
handleFail | function(state, action) | TBP | no | undefined | callback called if request has failed |
handleSuccess | function(state, action) | TBP | no | undefined | callback called if request is a success |
method | STRING | POST | no | 'GET' | http method for the request |
stateKey | string | foos | no | <computed from apiPath or url> | key into the store.getState().data.<stateKey> where normalized merged or deleted data will be applied |
url | string | https://momarx.com/foos | no | undefined | total url of the request that will be used if apiPath is not used |
fetch-normalize-data can play mainly with 3 types of actions:
REQUEST_DATA_(DELETE|GET|POST|PUT|PATCH)_(.*)
SUCCESS_DATA_(DELETE|GET|POST|PUT|PATCH)_(.*)
FAIL_DATA_(DELETE|GET|POST|PUT|PATCH)_(.*)
The action creator requestData is almost the only one you will need to use for fetching data at mount time or at event mutation time.
You can play with actions, but you need a special installation given the async action handler you take in your app:
See for example an example with https://github.com/betagouv/redux-thunk-data, but global use is like:
import { requestData } from 'fetch-normalize-data'
const config = {
apiPath: '/foos',
normalizer: {
'bar': {
stateKey: 'bars'
}
}
}
store.dispatch(requestData(config))
where config is all the possible config parameters you can find in
config of getNormalizedMergedState
or in the config of fetchData
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/4 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More