This commit is contained in:
2025-05-12 05:38:44 +09:00
parent dced21c3f8
commit 6d78bfa46e
8120 changed files with 1161564 additions and 0 deletions

1
book/node_modules/json-schema-defaults/.npmignore generated vendored Normal file
View File

@@ -0,0 +1 @@
test/

5
book/node_modules/json-schema-defaults/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.11"
- "0.10"
script: ./node_modules/.bin/jasmine-node test/ && ./node_modules/karma/bin/karma start --single-run --browsers="PhantomJS"

27
book/node_modules/json-schema-defaults/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
<a name="0.1.1"></a>
### 0.1.1 (2015-03-17)
#### Bug Fixes
* check object against null ([7c1139df]((https://github.com/chute/json-schema-defaults/commit/7c1139df4a7f6791d79bbaae12ef287870efb5b3))
* fix cloning array ([7cfca1c5]((https://github.com/chute/json-schema-defaults/commit/7cfca1c5eaa2da99663ccc31b65aeb18419f0400))
<a name="0.1.0"></a>
## 0.1.0 (2015-01-30)
* $ref and allOf property support (by @jhony-chikens) ([e2dd6c90](https://github.com/chute/json-schema-defaults/commit/e2dd6c904e6df7866f99c7691e1c63ecd7ff3ca5))
<a name="0.0.2"></a>
### 0.0.2 (2014-05-04)
#### Bug Fixes
* dont skip falsy values ([412e7613](https://github.com/chute/json-schema-defaults/commit/412e761359594642bbd9f4f75e600a257314b9a1))
<a name="0.0.1"></a>
### 0.0.1 (2014-04-28)
Initial version.

53
book/node_modules/json-schema-defaults/Gruntfile.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
options: {
globals: {
'require': true,
'define': true,
'module': true
},
trailing: true, // prevent trailing whitespace.
curly: true,
undef: true,
unused: true,
browser: true,
es3: true // prevent trailing commas.
},
build: {
files: {
src: ['lib/**/*.js']
}
}
},
bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: ['pkg'],
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json', 'bower.json', 'CHANGELOG.md'], // '-a' for all files
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: true,
pushTo: 'origin',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d' // options to use with '$ git describe'
}
},
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.registerTask('default', ['build']);
grunt.registerTask('build', ['jshint']);
};

21
book/node_modules/json-schema-defaults/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Chute Corporation
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.

120
book/node_modules/json-schema-defaults/Readme.md generated vendored Normal file
View File

@@ -0,0 +1,120 @@
# JSON Schema Defaults [![Build Status](https://travis-ci.org/chute/json-schema-defaults.svg?branch=master)](https://travis-ci.org/chute/json-schema-defaults)
> Generate JSON object from default values in JSON Schema
Works both in node and browser.
## Installation
- npm
```sh
npm install json-schema-defaults
```
- bower
```sh
bower install json-schema-defaults
```
- manual
Download [lib/defaults.js](lib/defaults.js)
## Usage
- CommonJS (node.js)
```js
var defaults = require('./path/to/index.js');
defaults({ ... });
```
- RequireJS
```js
// in require.js config
paths: {
'defaults': './path/to/lib/defaults.js'
}
// in a file
define(['defaults'], function(defaults) {
defaults({ ... });
});
```
- standalone
```js
window.jsonSchemaDefaults({ ... });
```
If the standalone version causes any conflict with existing `jsonSchemaDefaults` global variable,
you can return back the original variable:
```js
var defaults = window.jsonSchemaDefaults.noConflict();
// `window.jsonSchemaDefaults` now points to the original variable
// `defaults` points to this script
defaults({ ... });
```
## Documentation
Call `defaults` with JSON Schema. The default values will be extracted as a JSON.
```js
var json = defaults({
"title": "Album Options",
"type": "object",
"properties": {
"sort": {
"type": "string",
"default": "id"
},
"per_page": {
"default": 30,
"type": "integer"
}
}
});
// would return
{
sort: 'id',
per_page: 30
}
```
For more examples, see the tests.
## Development
Run tests
```sh
npm test
```
Or individually
```sh
# in node
./node_modules/.bin/jasmine-node test/
# in browser
./node_modules/karma/bin/karma start
```
## Contributors
* Eugene Tsypkin @jhony-chikens
## License
(c) 2015 Chute Corporation. Released under the terms of the MIT License.

27
book/node_modules/json-schema-defaults/bower.json generated vendored Normal file
View File

@@ -0,0 +1,27 @@
{
"name": "json-schema-defaults",
"main": "index.js",
"version": "0.1.1",
"authors": [
"Chute <hello@getchute.com>"
],
"description": "Generate JSON object from default values in JSON Schema",
"moduleType": [
"amd",
"globals",
"node"
],
"keywords": [
"json",
"schema"
],
"license": "MIT",
"homepage": "https://github.com/chute/json-schema-defaults",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}

1
book/node_modules/json-schema-defaults/index.js generated vendored Normal file
View File

@@ -0,0 +1 @@
module.exports = require('./lib/defaults');

68
book/node_modules/json-schema-defaults/karma.conf.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
// Karma configuration
// Generated on Mon Apr 28 2014 15:33:30 GMT-0700 (PDT)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'lib/*.js',
'test/**/*Spec.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};

192
book/node_modules/json-schema-defaults/lib/defaults.js generated vendored Normal file
View File

@@ -0,0 +1,192 @@
(function(root, factory) {
'use strict';
if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
// CommonJS
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD
define('json-schema-defaults', [], function() {
return factory();
});
} else {
// global with noConflict
var jsonSchemaDefaults = root.jsonSchemaDefaults;
root.jsonSchemaDefaults = factory();
root.jsonSchemaDefaults.noConflict = function() {
var defaults = root.jsonSchemaDefaults;
root.jsonSchemaDefaults = jsonSchemaDefaults;
return defaults;
};
}
}(this, function() {
'use strict';
/**
* check whether item is plain object
* @param {*} item
* @return {Boolean}
*/
var isObject = function(item) {
return typeof item === 'object' && item !== null && item.toString() === {}.toString();
};
/**
* deep JSON object clone
*
* @param {Object} source
* @return {Object}
*/
var cloneJSON = function(source) {
return JSON.parse(JSON.stringify(source));
};
/**
* returns a result of deep merge of two objects
*
* @param {Object} target
* @param {Object} source
* @return {Object}
*/
var merge = function(target, source) {
target = cloneJSON(target);
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (isObject(target[key]) && isObject(source[key])) {
target[key] = merge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
}
return target;
};
/**
* get object by reference. works only with local references that points on
* definitions object
*
* @param {String} path
* @param {Object} definitions
* @return {Object}
*/
var getLocalRef = function(path, definitions) {
path = path.replace(/^#\/definitions\//, '').split('/');
var find = function(path, root) {
var key = path.shift();
if (!root[key]) {
return {};
} else if (!path.length) {
return root[key];
} else {
return find(path, root[key]);
}
};
var result = find(path, definitions);
if (!isObject(result)) {
return result;
}
return cloneJSON(result);
};
/**
* merge list of objects from allOf properties
* if some of objects contains $ref field extracts this reference and merge it
*
* @param {Array} allOfList
* @param {Object} definitions
* @return {Object}
*/
var mergeAllOf = function(allOfList, definitions) {
var length = allOfList.length,
index = -1,
result = {};
while (++index < length) {
var item = allOfList[index];
item = (typeof item.$ref !== 'undefined') ? getLocalRef(item.$ref, definitions) : item;
result = merge(result, item);
}
return result;
};
/**
* returns a object that built with default values from json schema
*
* @param {Object} schema
* @param {Object} definitions
* @return {Object}
*/
var defaults = function(schema, definitions) {
if (typeof schema['default'] !== 'undefined') {
return schema['default'];
} else if (typeof schema.allOf !== 'undefined') {
var mergedItem = mergeAllOf(schema.allOf, definitions);
return defaults(mergedItem, definitions);
} else if (typeof schema.$ref !== 'undefined') {
var reference = getLocalRef(schema.$ref, definitions);
return defaults(reference, definitions);
} else if (schema.type === 'object') {
if (!schema.properties) { return {}; }
for (var key in schema.properties) {
if (schema.properties.hasOwnProperty(key)) {
schema.properties[key] = defaults(schema.properties[key], definitions);
if (typeof schema.properties[key] === 'undefined') {
delete schema.properties[key];
}
}
}
return schema.properties;
} else if (schema.type === 'array') {
if (!schema.items) { return []; }
return [defaults(schema.items, definitions)];
}
};
/**
* main function
*
* @param {Object} schema
* @param {Object|undefined} definitions
* @return {Object}
*/
return function (schema, definitions) {
if (typeof definitions === 'undefined') {
definitions = schema.definitions || {};
} else if (isObject(schema.definitions)) {
definitions = merge(definitions, schema.definitions);
}
return defaults(cloneJSON(schema), definitions);
};
}));

39
book/node_modules/json-schema-defaults/package.json generated vendored Normal file
View File

@@ -0,0 +1,39 @@
{
"name": "json-schema-defaults",
"version": "0.1.1",
"description": "Generate JSON object from default values in JSON Schema",
"homepage": "https://github.com/chute/grunt-json-schema-defaults",
"author": {
"name": "Chute",
"email": "hello@getchute.com"
},
"repository": {
"type": "git",
"url": "https://github.com/chute/json-schema-defaults.git"
},
"bugs": {
"url": "https://github.com/chute/json-schema-defaults/issues"
},
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/jasmine-node test/ && ./node_modules/karma/bin/karma start --single-run"
},
"keywords": [
"json",
"schema"
],
"license": "MIT",
"devDependencies": {
"karma": "~0.12.14",
"jasmine-node": "mhevery/jasmine-node#Jasmine2.0",
"karma-jasmine": "~0.1.5",
"karma-chrome-launcher": "~0.1.3",
"karma-firefox-launcher": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.4",
"grunt": "~0.4.4",
"grunt-bump": "0.0.13",
"grunt-conventional-changelog": "~1.1.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-jshint": "~0.10.0"
}
}