๐ OfilterJs is a data object filter processor for Javascript, which provides simpler, more convenient and more efficient data operations for development.
Installations
npm install ofilterjs
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM, UMD
Node Version
16.16.0
NPM Version
8.11.0
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (68.9%)
TypeScript (31.1%)
Developer
wenlng
Download Statistics
Total Downloads
1,425
Last Day
2
Last Week
14
Last Month
41
Last Year
535
GitHub Statistics
13 Stars
41 Commits
2 Forks
1 Watching
1 Branches
1 Contributors
Bundle Size
6.46 kB
Minified
2.24 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.7
Package Id
ofilterjs@1.0.7
Unpacked Size
228.27 kB
Size
31.11 kB
File Count
41
NPM Version
8.11.0
Node Version
16.16.0
Total Downloads
Cumulative downloads
Total Downloads
1,425
Last day
0%
2
Compared to previous day
Last week
16.7%
14
Compared to previous week
Last month
86.4%
41
Compared to previous month
Last year
90.4%
535
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
English | ไธญๆ
๐ OfilterJs is a data object filter processor for Javascript, which provides simpler, more convenient and more efficient data operations for development.
โญ๏ธ If it helps you, please give a star.
Supported languages
- Javascript
- TypeScript
Methods
- ๐
filterValue
- ๐
getValue
- ๐
resetValue
Install Module
1$ npm i ofilterjs
Or pnpm
, Or cnpm
, Or yarn
...
1$ pnpm i ofilterjs
Browser
1<script src="https://unpkg.com/ofilterjs@1.0.6/dist/ofilterjs.global.min.js"></script> 2 3<script> 4 console.log(ofilterjs) 5</script>
Import Module
1 const ofjs = require('ofilterjs') 2 3 // import ofjs from 'ofilterjs'
1. Data Filter
filterValue([Object{}], [Config], ...[extraData])
1.1 Filter or Recombine for data
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version_number: 10001 7 } 8 } 9} 10 11const newData = ofjs.filterValue(data, { 12 name: 'lib.pkg.name', 13 versionNumber: 'lib.pkg.version_number', 14}) 15console.log(newData) 16 17/** result 18 newData = { 19 name: 'ofilterjs', 20 versionNumber: 10001 21 } 22*/
1.2 Set value
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version_number: 10001 7 } 8 } 9} 10 11const newData = ofjs.filterValue(data, { 12 name: 'lib.pkg.name', 13 type: { 14 value: 'type value' 15 } 16}) 17console.log(newData) 18 19/** result 20 newData = { 21 name: 'ofilterjs', 22 type: 'type value' 23 } 24*/
1.3 Set default value
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version_number: 10001 7 } 8 } 9} 10 11const newData = ofjs.filterValue(data, { 12 name: 'lib.pkg.name', 13 alias: { 14 key: 'lib.pkg.alias', 15 default: 'Default alias' 16 }, 17 type: { 18 key: 'lib.pkg.type', 19 default: 'Npm pkg' 20 } 21}) 22console.log(newData) 23 24/** result 25 newData = { 26 name: 'ofilterjs', 27 alias: 'Default alias', 28 type: 'Npm pkg' 29 } 30*/
1.4 Custom filter callback
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version_number: 10001 7 } 8 } 9} 10 11const newData = ofjs.filterValue(data, { 12 name: 'lib.pkg.name', 13 alias: { 14 key: 'lib.pkg.alias', 15 filter: (value, source) => { 16 if (value !== '') return value 17 return 'This is ' + (source?.lib?.pkg?.name || 'unknown') 18 } 19 }, 20 type: { 21 key: 'lib.pkg.type', 22 filter: (value, source) => { 23 return 'Filter npm' 24 } 25 } 26}) 27console.log(newData) 28 29/** result 30 newData = { 31 name: 'ofilterjs', 32 alias: 'This is ofilterjs', 33 type: 'Filter npm' 34 } 35*/
1.5 Merge data of filter return to result
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version_number: 10001 7 } 8 } 9} 10 11const newData = ofjs.filterValue(data, { 12 name: 'lib.pkg.name', 13 _: { 14 merge: true, 15 filter: (_, source) => { 16 if (source?.lib?.pkg?.name === 'ofilterjs') { 17 return { 18 support: ['js', 'ts', 'es'] 19 } 20 } 21 return {} 22 } 23 }, 24 _1: { 25 merge: true, 26 filter: (_, source) => { 27 return { more: 'more data ...' } 28 } 29 }, 30 } 31}) 32console.log(newData) 33 34/** result 35 newData = { 36 name: 'ofilterjs', 37 support: ['js', 'ts', 'es'], 38 more: 'more data ...' 39 } 40*/
1.6 Merge extra data to result
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version_number: 10001 7 } 8 } 9} 10 11const newData = ofjs.filterValue(data, { 12 name: 'lib.pkg.name' 13 } 14}, { 15 name1: 'ofilter' 16}, { 17 name2: 'object filter' 18}) 19console.log(newData) 20 21/** result 22 newData = { 23 name: 'ofilterjs', 24 name1: 'ofilter', 25 name2: 'object filter' 26 } 27*/
2. Read Data
getValue([nameStr], [defaultValue])
2.1 Read Value / Deep Read for value
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 version: 10001 6 }, 7 support: ['js', 'ts', 'es'] 8 } 9} 10 11const name = ofjs.getValue(data, 'lib.pkg.name', 'unknown') 12console.log(name) // ofilterjs
2.2 Priority reading value
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version: 10001 7 }, 8 support: ['js', 'ts', 'es'] 9 } 10} 11 12const alias = ofjs.getValue(data, 'lib.pkg.alias|lib.pkg.name', 'unknown') 13console.log(name) // ofilterjs
2.3 Array index read
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version: 10001 7 }, 8 support: ['js', 'ts', 'es'] 9 } 10} 11 12const su = ofjs.getValue(data, 'lib.support.0', 'unknown') 13console.log(su) // js
3. Reset Data
resetValue([Object{}], [Config,?Optional])
Tip: Prefixes with '_' attribute names will not be reset automatically.
3.1 Auto set at data type
Shallow Reset
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version: 10001 7 }, 8 support: ['js', 'ts', 'es'], 9 _private: 'private attr' 10 }, 11 lib2: { 12 pkg: { 13 name: 'ofilter' 14 } 15 } 16} 17 18ofjs.resetValue(data, false) 19 20/** result 21const data = { 22 lib: {}, 23 lib2: {} 24} 25*/
Depth Reset
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version: 10001 7 }, 8 support: ['js', 'ts', 'es'], 9 _private: 'private attr' 10 }, 11 lib2: { 12 pkg: { 13 name: 'ofilter' 14 } 15 } 16} 17 18ofjs.resetValue(data, true) 19 20/** result 21const data = { 22 lib: { 23 pkg: { 24 name: '', 25 alias: '', 26 version: 0 27 }, 28 support: [], 29 _private: 'private attr' 30 }, 31 lib2: { 32 pkg: { 33 name: '' 34 } 35 } 36} 37*/
Depth Reset๏ผ Set depth layer parameter
1const data = { 2 // level 0 3 name: 'lib_list', 4 lib: { 5 // level 1 6 type: 'npm', 7 pkg: { 8 // level 2 9 name: 'ofilterjs', 10 alias: '', 11 version: 10001 12 }, 13 support: { 14 'js' : 'javascript', 15 'ts' : 'typescript' 16 }, 17 _private: 'private attr' 18 }, 19 lib2 : { 20 type: 'npm', 21 pkg: { 22 name: 'ofilter' 23 } 24 } 25} 26 27// 0 ~ (0+2) 28ofjs.resetValue(data, true, 2) 29 30/** result 31const data = { 32 // level 0 33 name: '', // Was reset 34 lib: { 35 // level 1 36 type: '', // Was reset 37 pkg: { 38 // level 2 39 name: 'ofilterjs', 40 alias: '', 41 version: 10001 42 }, 43 support: { 44 'js' : 'javascript', 45 'ts' : 'typescript' 46 }, 47 _private: 'private attr' 48 }, 49 lib2 : { 50 type: '', // Was reset 51 pkg: { 52 name: 'ofilter' 53 } 54 } 55} 56*/
Depth Reset๏ผ Set depth layer and start position parameter
1const data = { 2 // level 0 3 name: 'lib_list', 4 lib: { 5 // level 1 6 type: 'npm', 7 pkg: { 8 // level 2 9 name: 'ofilterjs', 10 alias: '', 11 version: 10001, 12 support: { 13 // level 3 14 'js' : 'javascript', 15 'ts' : 'typescript' 16 } 17 }, 18 _private: 'private attr' 19 }, 20 lib2 : { 21 type: 'npm', 22 pkg: { 23 name: 'ofilter' 24 } 25 } 26} 27 28// 1 ~ (1+2) 29ofjs.resetValue(data, true, 2, 1) 30 31/** result 32const data = { 33 // level 0 34 name: 'lib_list', 35 lib: { 36 // level 1 37 type: '', // Was reset 38 pkg: { 39 // level 2 40 name: '', // Was reset 41 alias: '', // Was reset 42 version: 0, // Was reset 43 support: { 44 // level 3 45 'js' : 'javascript', 46 'ts' : 'typescript' 47 } 48 }, 49 _private: 'private attr' 50 }, 51 lib2 : { 52 type: '', // Was reset 53 pkg: { 54 name: '' // Was reset 55 } 56 } 57}
3.2 Configuration reset field
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version: 10001 7 }, 8 support: ['js', 'ts', 'es'] 9 } 10} 11 12ofjs.resetValue(data, [ 13 'lib.pkg.name', 14 'lib.pkg.version' 15]) 16 17/** result 18const data = { 19 lib: { 20 pkg: { 21 name: '', 22 alias: '', 23 version: 0 24 }, 25 support: ['js', 'ts', 'es'] 26 } 27} 28*/
3.3 Configuration set data
1const data = { 2 lib: { 3 pkg: { 4 name: 'ofilterjs', 5 alias: '', 6 version: 10001 7 }, 8 support: ['js', 'ts', 'es'] 9 } 10} 11 12// us ofilterjs 13ofjs.resetValue(data, { 14 'lib.pkg.name': 'newname', 15 'lib.pkg.version': 10002 16}) 17 18/** result 19const data = { 20 lib: { 21 pkg: { 22 name: 'newname', 23 alias: '', 24 version: 10002 25 }, 26 support: ['js', 'ts', 'es'] 27 } 28} 29*/
Buy the author coffee: http://witkeycode.com/sponsor
LICENSE
MIT
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.