🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

latest-lib

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

latest-lib - npm Package Compare versions

Comparing version
0.1.2
to
0.2.0
+15
-7
index.js

@@ -8,2 +8,4 @@ 'use strict';

return new Promise((resolve, reject) => {
let desiredMajor = null;
if (!name) {

@@ -13,2 +15,6 @@ return reject(new Error(`Please specify the name of the library`));

if (name.indexOf('@') > -1) {
[name, desiredMajor] = name.split('@');
}
got(`https://api.cdnjs.com/libraries?search=${name}&fields=version,assets`, {json: true})

@@ -20,12 +26,14 @@ .then(res => {

const versionAssets = library.assets.filter(files => {
if (desiredMajor) {
return new RegExp(`^${desiredMajor}`).test(files.version) === true;
}
return files.version === library.version;
});
// https://cdnjs.cloudflare.com/ajax/libs/[library]/[version]/[files]
const rootDirectory = library.latest.substring(
0,
(library.latest.indexOf(library.version) +
library.version.length)
).concat('/');
// Return only the latest version
let files = versionAssets[0].files.map(item => urlResolve(rootDirectory, item));
let files = versionAssets[0].files.map(item => urlResolve(
`https://cdnjs.cloudflare.com/ajax/libs/${library.name}/${versionAssets[0].version}/`,
item)
);

@@ -32,0 +40,0 @@ if (opts && opts.only) {

{
"name": "latest-lib",
"version": "0.1.2",
"version": "0.2.0",
"description": "Get the latest version of a CSS or JavaScript library hosted on CDNJS",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -18,3 +18,3 @@ # latest-lib [![Build Status](https://travis-ci.org/GabrielMangiurea/latest-lib.svg?branch=master)](https://travis-ci.org/GabrielMangiurea/latest-lib)

// search for bootstrap
// search for the latest version of bootstrap
latestLib('bootstrap')

@@ -24,2 +24,8 @@ .then(library => console.log(library))

.catch(err => console.log(err));
// search for the latest version of bootstrap 3
latestLib('bootstrap@3')
.then(library => console.log(library))
//=> {name: 'twitter-bootstrap', version: '3.3.7', files: [...]}
.catch(err => console.log(err));
```

@@ -32,2 +38,13 @@

Returns a `Promise` containing an object with the following properties:
- On success:
- **name** `String`
- **version** `String`
- **files** `Array`
- On error:
- an `Error` object
#### name

@@ -39,2 +56,4 @@

Suffixing the name with `@[number]` will fetch the latest version of `[number]` major release
#### opts

@@ -41,0 +60,0 @@

@@ -21,2 +21,9 @@ 'use strict';

test('success: should return the correct major version when specified', async t => {
const f = await m('bootstrap@3');
t.is(f.version, '3.3.7');
// Resource URLs should also include the correct version number
t.true(f.files[0].indexOf('3.3.7') > -1);
});
test('failure: should return an error object', async t => {

@@ -23,0 +30,0 @@ await m()