Skip to content

Commit 98e8e7a

Browse files
committed
initial commit
0 parents  commit 98e8e7a

14 files changed

+1875
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
node_modules
3+
*.d.ts
4+
dist

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- "8"
4+
5+
env:
6+
global:
7+
- BUILD_TIMEOUT=10000

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TODO changelog
2+
3+
## 1.0.0
4+
5+
* First release

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2019 Rich Harris
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# object-cull
2+
3+
Create a copy of an object, based on which properties were accessed.
4+
5+
```js
6+
import { prepare, apply } from 'object-cull';
7+
8+
const proxy = prepare({
9+
firstname: 'Terrell',
10+
lastname: 'Snider',
11+
friends: [
12+
{ firstname: 'Rachelle', lastname: 'Knight' },
13+
{ firstname: 'Ila', lastname: 'Farrell' },
14+
{ firstname: 'Vasquez', lastname: 'Flynn' }
15+
],
16+
pets: [
17+
{ name: 'Bobo', species: 'Great Dane' }
18+
]
19+
});
20+
21+
console.log(proxy.firstname); // Terrell
22+
console.log(proxy.friends[0].firstname); // Rachelle
23+
24+
const { kept, culled } = apply(proxy);
25+
26+
console.log(kept);
27+
/*
28+
{ firstname: 'Terrell', friends: [ { firstname: 'Rachelle' } ] }
29+
*/
30+
31+
console.log(culled);
32+
/*
33+
[
34+
{ path: 'lastname', value: 'Snider' },
35+
{ path: 'friends.0.lastname', value: 'Knight' },
36+
{ path: 'friends.1', value: { firstname: 'Ila', lastname: 'Farrell' } },
37+
{ path: 'friends.2', value: { firstname: 'Vasquez', lastname: 'Flynn' } },
38+
{ path: 'pets', value: [ { name: 'Bobo', species: 'Great Dane' } ] }
39+
]
40+
*/
41+
42+
const { prepare, apply } = require('./');
43+
44+
const proxy = prepare({
45+
firstname: 'Terrell',
46+
lastname: 'Snider',
47+
friends: [
48+
{ firstname: 'Rachelle', lastname: 'Knight' },
49+
{ firstname: 'Ila', lastname: 'Farrell' },
50+
{ firstname: 'Vasquez', lastname: 'Flynn' }
51+
],
52+
pets: [
53+
{ name: 'Bobo', species: 'Great Dane' }
54+
]
55+
});
56+
57+
console.log(proxy.firstname); // Terrell
58+
console.log(proxy.friends[0].firstname); // Rachelle
59+
60+
const { kept, culled } = apply(proxy);
61+
62+
console.log(kept);
63+
/*
64+
{ firstname: 'Terrell', friends: [ { firstname: 'Rachelle' } ] }
65+
*/
66+
67+
console.log(culled);
68+
/*
69+
[
70+
{ path: 'lastname', value: 'Snider' },
71+
{ path: 'friends.0.lastname', value: 'Knight' },
72+
{ path: 'friends.1', value: { firstname: 'Ila', lastname: 'Farrell' } },
73+
{ path: 'friends.2', value: { firstname: 'Vasquez', lastname: 'Flynn' } },
74+
{ path: 'pets', value: [ { name: 'Bobo', species: 'Great Dane' } ] }
75+
]
76+
*/
77+
78+
const unused_bytes = culled.reduce((total, item) => {
79+
return total + JSON.stringify(item.value).length;
80+
}, 0);
81+
82+
const percent_unused = 100 * unused_bytes / JSON.stringify(proxy).length;
83+
84+
console.log(`${percent_unused}% of the data was unused`);
85+
```
86+
87+
88+
## Why?
89+
90+
Mostly for server-side rendering. You might not to serialize *all* your data to send it to the client.
91+
92+
93+
## Prior art
94+
95+
* [js-off](https://github.com/reconbot/js-off)
96+
97+
98+
## License
99+
100+
MIT

appveyor.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# http://www.appveyor.com/docs/appveyor-yml
2+
3+
version: "{build}"
4+
5+
clone_depth: 10
6+
7+
init:
8+
- git config --global core.autocrlf false
9+
10+
environment:
11+
matrix:
12+
# node.js
13+
- nodejs_version: 8
14+
15+
install:
16+
- ps: Install-Product node $env:nodejs_version
17+
- npm install
18+
19+
build: off
20+
21+
test_script:
22+
- node --version && npm --version
23+
- npm test
24+
25+
matrix:
26+
fast_finish: false
27+
28+
# cache:
29+
# - C:\Users\appveyor\AppData\Roaming\npm-cache -> package.json # npm cache
30+
# - node_modules -> package.json # local npm modules

mocha.opts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--require sucrase/register
2+
test/test.ts

0 commit comments

Comments
 (0)