alexa-ssml
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -42,3 +42,3 @@ 'use strict'; | ||
val = (0, _kebabCase2.default)(val || ""); | ||
return this.assertLegalChar(val); | ||
return val; | ||
} | ||
@@ -72,5 +72,9 @@ }; | ||
var xml = _xmlbuilder2.default.create(data.tag, {}, {}, { stringify: stringify }); | ||
var xml = _xmlbuilder2.default.create(data.tag, { | ||
stringify: stringify, | ||
headless: true | ||
}); | ||
renderNode(data.children, xml); | ||
return xml.end({ pretty: true }); | ||
} |
@@ -8,43 +8,43 @@ 'use strict'; | ||
var _audio2 = require('../schema/audio'); | ||
var _audio2 = require('./types/audio'); | ||
var _audio3 = _interopRequireDefault(_audio2); | ||
var _audio = _interopRequireWildcard(_audio2); | ||
var _pause2 = require('../schema/pause'); | ||
var _pause2 = require('./types/pause'); | ||
var _pause3 = _interopRequireDefault(_pause2); | ||
var _pause = _interopRequireWildcard(_pause2); | ||
var _p2 = require('../schema/p'); | ||
var _p2 = require('./types/p'); | ||
var _p3 = _interopRequireDefault(_p2); | ||
var _p = _interopRequireWildcard(_p2); | ||
var _phoneme2 = require('../schema/phoneme'); | ||
var _phoneme2 = require('./types/phoneme'); | ||
var _phoneme3 = _interopRequireDefault(_phoneme2); | ||
var _phoneme = _interopRequireWildcard(_phoneme2); | ||
var _s2 = require('../schema/s'); | ||
var _s2 = require('./types/s'); | ||
var _s3 = _interopRequireDefault(_s2); | ||
var _s = _interopRequireWildcard(_s2); | ||
var _sayAs = require('../schema/sayAs'); | ||
var _sayAs = require('./types/sayAs'); | ||
var _sayAs2 = _interopRequireDefault(_sayAs); | ||
var _sayas = _interopRequireWildcard(_sayAs); | ||
var _speak2 = require('../schema/speak'); | ||
var _speak2 = require('./types/speak'); | ||
var _speak3 = _interopRequireDefault(_speak2); | ||
var _speak = _interopRequireWildcard(_speak2); | ||
var _w2 = require('../schema/w'); | ||
var _w2 = require('./types/w'); | ||
var _w3 = _interopRequireDefault(_w2); | ||
var _w = _interopRequireWildcard(_w2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
exports.audio = _audio3.default; | ||
exports.pause = _pause3.default; | ||
exports.p = _p3.default; | ||
exports.phoneme = _phoneme3.default; | ||
exports.s = _s3.default; | ||
exports.sayas = _sayAs2.default; | ||
exports.speak = _speak3.default; | ||
exports.w = _w3.default; | ||
exports.audio = _audio; | ||
exports.pause = _pause; | ||
exports.p = _p; | ||
exports.phoneme = _phoneme; | ||
exports.s = _s; | ||
exports.sayas = _sayas; | ||
exports.speak = _speak; | ||
exports.w = _w; |
@@ -10,5 +10,5 @@ 'use strict'; | ||
var _tv = require('tv4'); | ||
var _get = require('lodash/get'); | ||
var _tv2 = _interopRequireDefault(_tv); | ||
var _get2 = _interopRequireDefault(_get); | ||
@@ -19,10 +19,2 @@ var _flatten = require('lodash/flatten'); | ||
var _get = require('lodash/get'); | ||
var _get2 = _interopRequireDefault(_get); | ||
var _omit = require('lodash/omit'); | ||
var _omit2 = _interopRequireDefault(_omit); | ||
var _schema = require('./schema'); | ||
@@ -32,2 +24,4 @@ | ||
var _validateProps = require('./validateProps'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -44,19 +38,18 @@ | ||
// handle custom elements (only functions for now) | ||
if (typeof tag === "function") return tag(_extends({}, props, { children: children })); | ||
// make sure we have a valid tag | ||
if (typeof tag !== "string") throw new Error('Invalid tag: ' + tag); | ||
var schema = schemas[tag.toLowerCase()]; | ||
if (!schema) throw new Error('Unknown tag: ' + tag); | ||
// make sure we have a known tag | ||
var type = schemas[tag.toLowerCase()]; | ||
if (!type) throw new Error('Unknown tag: ' + tag); | ||
props = (0, _omit2.default)(props, 'children'); | ||
// validate and transform props | ||
props = (0, _validateProps.validateProps)(props, type.schema); | ||
props = type.transform(props); | ||
var _tv4$validateResult = _tv2.default.validateResult(props, schema, false, true); | ||
var error = _tv4$validateResult.error; | ||
if (error) throw new Error('Invalid value for property ' + error.dataPath.slice(1) + ': ' + error.message); | ||
return { | ||
tag: schema.tag, | ||
tag: type.tag, | ||
props: props, | ||
@@ -63,0 +56,0 @@ children: children |
{ | ||
"name": "alexa-ssml", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -7,3 +7,8 @@ # alexa-ssml [![Build Status](https://travis-ci.org/nickclaw/alexa-ssml.svg?branch=master)](https://travis-ci.org/nickclaw/alexa-ssml) | ||
* Only supports [limited syntax](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/speech-synthesis-markup-language-ssml-reference) | ||
* Camel case tag names and properties. | ||
* `<break />` changed to `<pause />` | ||
* Compatible with `transform-react-jsx` [babel plugin](https://babeljs.io/docs/plugins/transform-react-jsx/) | ||
### Example | ||
@@ -29,3 +34,3 @@ | ||
``` | ||
```js | ||
/** @jsx ssml */ | ||
@@ -46,7 +51,12 @@ | ||
### Caveats | ||
* Only supports [limited syntax](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/speech-synthesis-markup-language-ssml-reference) | ||
* Only supports `camelCase` tag names and properties. | ||
* `<break />` -> `<pause />` due to javascript reserved words. | ||
* Must use with `transform-react-jsx` [babel plugin](https://babeljs.io/docs/plugins/transform-react-jsx/). | ||
### API | ||
##### `ssml(tag, props, ...children) -> object` | ||
* `tag` can be a string or function | ||
* Use `/** @jsx ssml */` to support jsx syntax | ||
* Returns object like `{ tag, props, children }` | ||
##### `renderToString(data) -> string` | ||
* Takes in object from `ssml` function | ||
* Must be wrapped in a `"speak"` tag |
@@ -50,6 +50,2 @@ /** @jsx ssml */ | ||
it('should validate properties on tags', function() { | ||
}); | ||
it('should return an object', function() { | ||
@@ -56,0 +52,0 @@ const data = ( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22198
493
60
24
1