Installations
npm install fetch-normalize-data
Developer Guide
Typescript
No
Module System
CommonJS
Score
67.7
Supply Chain
99
Quality
82.3
Maintenance
100
Vulnerability
80.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.35%)
Shell (0.65%)
Developer
betagouv
Download Statistics
Total Downloads
94,195
Last Day
6
Last Week
33
Last Month
232
Last Year
2,406
GitHub Statistics
7 Stars
326 Commits
1 Forks
9 Watching
18 Branches
20 Contributors
Bundle Size
92.59 kB
Minified
22.89 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
94,195
Last day
0%
6
Compared to previous day
Last week
13.8%
33
Compared to previous week
Last month
18.4%
232
Compared to previous month
Last year
-54.1%
2,406
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
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.
Basic Usage
Merge
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}
Delete
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}
Usage with config
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 |
Fetch usage
fetchData
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 |
Reducer usage
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.
requestData
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Mozilla Public License 2.0: LICENSE:0
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
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
18 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.7
/10
Last Scanned on 2025-02-03
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 MoreOther packages similar to 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.