RequireJS CDN test
Using RequireJS to load from a CDN
See: https://github.com/jherax/proxy-storage
HTML
<script src="http://requirejs.org/docs/release/2.1.5/minified/require.js"></script>
<div id="test">It doesn't work :( </div>
CSS
#test {
color: orangered;
line-height: 24px;
}
JavaScript
requirejs.config({
paths: {
'array-sort-by': 'https://unpkg.com/array-sort-by/dist/sort-by.min'
}
});
require(['array-sort-by'], function(sortBy) {
var arr = ['á', 'e', 'ú', 'c'];
console.info(JSON.stringify(arr));
console.info('Sorting accented characters');
console.log(JSON.stringify(sortBy(arr)), '\n\n');
/**
* expected:
* ["á", "c", "e", "ú"]
*/
arr = ['único', 'cosas', 'Árbol', 'fútbol', 'algo'];
console.info(JSON.stringify(arr));
console.info('Sorting accented characters');
console.log(JSON.stringify(sortBy(arr)));
/**
* expected:
* ["algo", "Árbol", "cosas", "fútbol", "único"]
*/
sortBy(arr, item => 'desc:' + item);
console.log(JSON.stringify(arr), '\n\n');
/**
* expected:
* ["único", "fútbol", "cosas", "Árbol", "algo"]
*/
arr = [
{ a: 9, age: 26, name: "pedro" },
{ a: 6, age: 21, name: "Pedro" },
{ a: 7, age: 26, name: "Maria" },
{ a: 2, age: 26, name: "maría" }
];
console.info(JSON.stringify(arr));
console.info('Sorting ASC by @name, after DESC by @age, after ASC by @a');
sortBy(arr, item => [item.name, -item.age, item.a]);
console.log(JSON.stringify(arr));
/**
* expected:
* [
* { a: 2, age: 26, name: "maría" },
* { a: 7, age: 26, name: "Maria" },
* { a: 9, age: 26, name: "pedro" },
* { a: 6, age: 21, name: "Pedro" }
* ]
*/
document.getElementById('test').innerHTML = "It works!<br>See the results in console.";
});