mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 18:52:50 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
2
node_modules/mpath/.npmignore
generated
vendored
Normal file
2
node_modules/mpath/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.sw*
|
||||
node_modules/
|
||||
4
node_modules/mpath/.travis.yml
generated
vendored
Normal file
4
node_modules/mpath/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
||||
16
node_modules/mpath/History.md
generated
vendored
Normal file
16
node_modules/mpath/History.md
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
0.1.1 / 2012-12-21
|
||||
==================
|
||||
|
||||
* added; map support
|
||||
|
||||
0.1.0 / 2012-12-13
|
||||
==================
|
||||
|
||||
* added; set('array.property', val, object) support
|
||||
* added; get('array.property', object) support
|
||||
|
||||
0.0.1 / 2012-11-03
|
||||
==================
|
||||
|
||||
* initial release
|
||||
22
node_modules/mpath/LICENSE
generated
vendored
Normal file
22
node_modules/mpath/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012 [Aaron Heckmann](aaron.heckmann+github@gmail.com)
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
5
node_modules/mpath/Makefile
generated
vendored
Normal file
5
node_modules/mpath/Makefile
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
test:
|
||||
@node_modules/mocha/bin/mocha -A $(T)
|
||||
|
||||
.PHONY: test
|
||||
278
node_modules/mpath/README.md
generated
vendored
Normal file
278
node_modules/mpath/README.md
generated
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
#mpath
|
||||
|
||||
{G,S}et javascript object values using MongoDB-like path notation.
|
||||
|
||||
###Getting
|
||||
|
||||
```js
|
||||
var mpath = require('mpath');
|
||||
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.get('comments.1.title', obj) // 'exciting!'
|
||||
```
|
||||
|
||||
`mpath.get` supports array property notation as well.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.get('comments.title', obj) // ['funny', 'exciting!']
|
||||
```
|
||||
|
||||
Array property and indexing syntax, when used together, are very powerful.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
array: [
|
||||
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
|
||||
, { o: { array: [{x: {b: [1,2,3]}}, { x: {z: 10 }}, { x: 'Turkey Day' }] }}
|
||||
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
|
||||
, { o: { array: [{x: null }] }}
|
||||
, { o: { array: [{y: 3 }] }}
|
||||
, { o: { array: [3, 0, null] }}
|
||||
, { o: { name: 'ha' }}
|
||||
];
|
||||
}
|
||||
|
||||
var found = mpath.get('array.o.array.x.b.1', obj);
|
||||
|
||||
console.log(found); // prints..
|
||||
|
||||
[ [6, undefined]
|
||||
, [2, undefined, undefined]
|
||||
, [null, 1]
|
||||
, [null]
|
||||
, [undefined]
|
||||
, [undefined, undefined, undefined]
|
||||
, undefined
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
#####Field selection rules:
|
||||
|
||||
The following rules are iteratively applied to each `segment` in the passed `path`. For example:
|
||||
|
||||
```js
|
||||
var path = 'one.two.14'; // path
|
||||
'one' // segment 0
|
||||
'two' // segment 1
|
||||
14 // segment 2
|
||||
```
|
||||
|
||||
- 1) when value of the segment parent is not an array, return the value of `parent.segment`
|
||||
- 2) when value of the segment parent is an array
|
||||
- a) if the segment is an integer, replace the parent array with the value at `parent[segment]`
|
||||
- b) if not an integer, keep the array but replace each array `item` with the value returned from calling `get(remainingSegments, item)` or undefined if falsey.
|
||||
|
||||
#####Maps
|
||||
|
||||
`mpath.get` also accepts an optional `map` argument which receives each individual found value. The value returned from the `map` function will be used in the original found values place.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.get('comments.title', obj, function (val) {
|
||||
return 'funny' == val
|
||||
? 'amusing'
|
||||
: val;
|
||||
});
|
||||
// ['amusing', 'exciting!']
|
||||
```
|
||||
|
||||
###Setting
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.set('comments.1.title', 'hilarious', obj)
|
||||
console.log(obj.comments[1].title) // 'hilarious'
|
||||
```
|
||||
|
||||
`mpath.set` supports the same array property notation as `mpath.get`.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.set('comments.title', ['hilarious', 'fruity'], obj);
|
||||
|
||||
console.log(obj); // prints..
|
||||
|
||||
{ comments: [
|
||||
{ title: 'hilarious' },
|
||||
{ title: 'fruity' }
|
||||
]}
|
||||
```
|
||||
|
||||
Array property and indexing syntax can be used together also when setting.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
array: [
|
||||
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
|
||||
, { o: { array: [{x: {b: [1,2,3]}}, { x: {z: 10 }}, { x: 'Turkey Day' }] }}
|
||||
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
|
||||
, { o: { array: [{x: null }] }}
|
||||
, { o: { array: [{y: 3 }] }}
|
||||
, { o: { array: [3, 0, null] }}
|
||||
, { o: { name: 'ha' }}
|
||||
]
|
||||
}
|
||||
|
||||
mpath.set('array.1.o', 'this was changed', obj);
|
||||
|
||||
console.log(require('util').inspect(obj, false, 1000)); // prints..
|
||||
|
||||
{
|
||||
array: [
|
||||
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
|
||||
, { o: 'this was changed' }
|
||||
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
|
||||
, { o: { array: [{x: null }] }}
|
||||
, { o: { array: [{y: 3 }] }}
|
||||
, { o: { array: [3, 0, null] }}
|
||||
, { o: { name: 'ha' }}
|
||||
];
|
||||
}
|
||||
|
||||
mpath.set('array.o.array.x', 'this was changed too', obj);
|
||||
|
||||
console.log(require('util').inspect(obj, false, 1000)); // prints..
|
||||
|
||||
{
|
||||
array: [
|
||||
{ o: { array: [{x: 'this was changed too'}, { y: 10, x: 'this was changed too'} ] }}
|
||||
, { o: 'this was changed' }
|
||||
, { o: { array: [{x: 'this was changed too'}, { x: 'this was changed too'}] }}
|
||||
, { o: { array: [{x: 'this was changed too'}] }}
|
||||
, { o: { array: [{x: 'this was changed too', y: 3 }] }}
|
||||
, { o: { array: [3, 0, null] }}
|
||||
, { o: { name: 'ha' }}
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
####Setting arrays
|
||||
|
||||
By default, setting a property within an array to another array results in each element of the new array being set to the item in the destination array at the matching index. An example is helpful.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.set('comments.title', ['hilarious', 'fruity'], obj);
|
||||
|
||||
console.log(obj); // prints..
|
||||
|
||||
{ comments: [
|
||||
{ title: 'hilarious' },
|
||||
{ title: 'fruity' }
|
||||
]}
|
||||
```
|
||||
|
||||
If we do not desire this destructuring-like assignment behavior we may instead specify the `$` operator in the path being set to force the array to be copied directly.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.set('comments.$.title', ['hilarious', 'fruity'], obj);
|
||||
|
||||
console.log(obj); // prints..
|
||||
|
||||
{ comments: [
|
||||
{ title: ['hilarious', 'fruity'] },
|
||||
{ title: ['hilarious', 'fruity'] }
|
||||
]}
|
||||
```
|
||||
|
||||
####Field assignment rules
|
||||
|
||||
The rules utilized mirror those used on `mpath.get`, meaning we can take values returned from `mpath.get`, update them, and reassign them using `mpath.set`. Note that setting nested arrays of arrays can get unweildy quickly. Check out the [tests](https://github.com/aheckmann/mpath/blob/master/test/index.js) for more extreme examples.
|
||||
|
||||
#####Maps
|
||||
|
||||
`mpath.set` also accepts an optional `map` argument which receives each individual value being set. The value returned from the `map` function will be used in the original values place.
|
||||
|
||||
```js
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'funny' },
|
||||
{ title: 'exciting!' }
|
||||
]
|
||||
}
|
||||
|
||||
mpath.set('comments.title', ['hilarious', 'fruity'], obj, function (val) {
|
||||
return val.length;
|
||||
});
|
||||
|
||||
console.log(obj); // prints..
|
||||
|
||||
{ comments: [
|
||||
{ title: 9 },
|
||||
{ title: 6 }
|
||||
]}
|
||||
```
|
||||
|
||||
### Custom object types
|
||||
|
||||
Sometimes you may want to enact the same functionality on custom object types that store all their real data internally, say for an ODM type object. No fear, `mpath` has you covered. Simply pass the name of the property being used to store the internal data and it will be traversed instead:
|
||||
|
||||
```js
|
||||
var mpath = require('mpath');
|
||||
|
||||
var obj = {
|
||||
comments: [
|
||||
{ title: 'exciting!', _doc: { title: 'great!' }}
|
||||
]
|
||||
}
|
||||
|
||||
mpath.get('comments.0.title', obj, '_doc') // 'great!'
|
||||
mpath.set('comments.0.title', 'nov 3rd', obj, '_doc')
|
||||
mpath.get('comments.0.title', obj, '_doc') // 'nov 3rd'
|
||||
mpath.get('comments.0.title', obj) // 'exciting'
|
||||
```
|
||||
|
||||
When used with a `map`, the `map` argument comes last.
|
||||
|
||||
```js
|
||||
mpath.get(path, obj, '_doc', map);
|
||||
mpath.set(path, val, obj, '_doc', map);
|
||||
```
|
||||
|
||||
[LICENSE](https://github.com/aheckmann/mpath/blob/master/LICENSE)
|
||||
|
||||
1
node_modules/mpath/index.js
generated
vendored
Normal file
1
node_modules/mpath/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = exports = require('./lib');
|
||||
183
node_modules/mpath/lib/index.js
generated
vendored
Normal file
183
node_modules/mpath/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
|
||||
/**
|
||||
* Returns the value of object `o` at the given `path`.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* var obj = {
|
||||
* comments: [
|
||||
* { title: 'exciting!', _doc: { title: 'great!' }}
|
||||
* , { title: 'number dos' }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* mpath.get('comments.0.title', o) // 'exciting!'
|
||||
* mpath.get('comments.0.title', o, '_doc') // 'great!'
|
||||
* mpath.get('comments.title', o) // ['exciting!', 'number dos']
|
||||
*
|
||||
* // summary
|
||||
* mpath.get(path, o)
|
||||
* mpath.get(path, o, special)
|
||||
* mpath.get(path, o, map)
|
||||
* mpath.get(path, o, special, map)
|
||||
*
|
||||
* @param {String} path
|
||||
* @param {Object} o
|
||||
* @param {String} [special] When this property name is present on any object in the path, walking will continue on the value of this property.
|
||||
* @param {Function} [map] Optional function which receives each individual found value. The value returned from `map` is used in the original values place.
|
||||
*/
|
||||
|
||||
exports.get = function (path, o, special, map) {
|
||||
if ('function' == typeof special) {
|
||||
map = special;
|
||||
special = undefined;
|
||||
}
|
||||
|
||||
map || (map = K);
|
||||
|
||||
var parts = 'string' == typeof path
|
||||
? path.split('.')
|
||||
: path
|
||||
|
||||
if (!Array.isArray(parts)) {
|
||||
throw new TypeError('Invalid `path`. Must be either string or array');
|
||||
}
|
||||
|
||||
var obj = o
|
||||
, part;
|
||||
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
part = parts[i];
|
||||
|
||||
if (Array.isArray(obj) && !/^\d+$/.test(part)) {
|
||||
// reading a property from the array items
|
||||
var paths = parts.slice(i);
|
||||
|
||||
return obj.map(function (item) {
|
||||
return item
|
||||
? exports.get(paths, item, special, map)
|
||||
: map(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
obj = special && obj[special]
|
||||
? obj[special][part]
|
||||
: obj[part];
|
||||
|
||||
if (!obj) return map(obj);
|
||||
}
|
||||
|
||||
return map(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `val` at the given `path` of object `o`.
|
||||
*
|
||||
* @param {String} path
|
||||
* @param {Anything} val
|
||||
* @param {Object} o
|
||||
* @param {String} [special] When this property name is present on any object in the path, walking will continue on the value of this property.
|
||||
* @param {Function} [map] Optional function which is passed each individual value before setting it. The value returned from `map` is used in the original values place.
|
||||
|
||||
*/
|
||||
|
||||
exports.set = function (path, val, o, special, map, _copying) {
|
||||
if ('function' == typeof special) {
|
||||
map = special;
|
||||
special = undefined;
|
||||
}
|
||||
|
||||
map || (map = K);
|
||||
|
||||
var parts = 'string' == typeof path
|
||||
? path.split('.')
|
||||
: path
|
||||
|
||||
if (!Array.isArray(parts)) {
|
||||
throw new TypeError('Invalid `path`. Must be either string or array');
|
||||
}
|
||||
|
||||
if (null == o) return;
|
||||
|
||||
// the existance of $ in a path tells us if the user desires
|
||||
// the copying of an array instead of setting each value of
|
||||
// the array to the one by one to matching positions of the
|
||||
// current array.
|
||||
var copy = _copying || /\$/.test(path)
|
||||
, obj = o
|
||||
, part
|
||||
|
||||
for (var i = 0, len = parts.length - 1; i < len; ++i) {
|
||||
part = parts[i];
|
||||
|
||||
if ('$' == part) {
|
||||
if (i == len - 1) {
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(obj) && !/^\d+$/.test(part)) {
|
||||
var paths = parts.slice(i);
|
||||
if (!copy && Array.isArray(val)) {
|
||||
for (var j = 0; j < obj.length && j < val.length; ++j) {
|
||||
// assignment of single values of array
|
||||
exports.set(paths, val[j], obj[j], special, map, copy);
|
||||
}
|
||||
} else {
|
||||
for (var j = 0; j < obj.length; ++j) {
|
||||
// assignment of entire value
|
||||
exports.set(paths, val, obj[j], special, map, copy);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
obj = special && obj[special]
|
||||
? obj[special][part]
|
||||
: obj[part];
|
||||
|
||||
if (!obj) return;
|
||||
}
|
||||
|
||||
// process the last property of the path
|
||||
|
||||
part = parts[len];
|
||||
|
||||
// use the special property if exists
|
||||
if (special && obj[special]) {
|
||||
obj = obj[special];
|
||||
}
|
||||
|
||||
// set the value on the last branch
|
||||
if (Array.isArray(obj) && !/^\d+$/.test(part)) {
|
||||
if (!copy && Array.isArray(val)) {
|
||||
for (var item, j = 0; j < obj.length && j < val.length; ++j) {
|
||||
item = obj[j];
|
||||
if (item) {
|
||||
if (item[special]) item = item[special];
|
||||
item[part] = map(val[j]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var j = 0; j < obj.length; ++j) {
|
||||
item = obj[j];
|
||||
if (item) {
|
||||
if (item[special]) item = item[special];
|
||||
item[part] = map(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
obj[part] = map(val);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the value passed to it.
|
||||
*/
|
||||
|
||||
function K (v) {
|
||||
return v;
|
||||
}
|
||||
78
node_modules/mpath/package.json
generated
vendored
Normal file
78
node_modules/mpath/package.json
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"mpath@0.1.1",
|
||||
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/mongoose"
|
||||
]
|
||||
],
|
||||
"_from": "mpath@0.1.1",
|
||||
"_id": "mpath@0.1.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/mpath",
|
||||
"_npmUser": {
|
||||
"email": "aaron.heckmann+github@gmail.com",
|
||||
"name": "aaron"
|
||||
},
|
||||
"_npmVersion": "1.1.59",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "mpath",
|
||||
"raw": "mpath@0.1.1",
|
||||
"rawSpec": "0.1.1",
|
||||
"scope": null,
|
||||
"spec": "0.1.1",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mongoose"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/mpath/-/mpath-0.1.1.tgz",
|
||||
"_shasum": "23da852b7c232ee097f4759d29c0ee9cd22d5e46",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "mpath@0.1.1",
|
||||
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/mongoose",
|
||||
"author": {
|
||||
"email": "aaron.heckmann+github@gmail.com",
|
||||
"name": "Aaron Heckmann"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/aheckmann/mpath/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "{G,S}et object values using MongoDB path notation",
|
||||
"devDependencies": {
|
||||
"mocha": "1.6.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "23da852b7c232ee097f4759d29c0ee9cd22d5e46",
|
||||
"tarball": "http://registry.npmjs.org/mpath/-/mpath-0.1.1.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/aheckmann/mpath#readme",
|
||||
"keywords": [
|
||||
"get",
|
||||
"mongodb",
|
||||
"path",
|
||||
"set"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "aaron",
|
||||
"email": "aaron.heckmann+github@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "mpath",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/aheckmann/mpath.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "0.1.1"
|
||||
}
|
||||
1630
node_modules/mpath/test/index.js
generated
vendored
Normal file
1630
node_modules/mpath/test/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user