Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@procore/cdn

Package Overview
Dependencies
Maintainers
18
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@procore/cdn - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

CHANGELOG.md

27

__tests__/cdn.test.js
const cdn = require('./../cdn');
var asset1 = 'https://assset%d.cdn.com/test.png';
var asset2 = 'https://assset%d.cdn.com/test.jpg';
var asset3 = 'https://assset%d.cdn.com/test.jpg?size=sm';
var asset4 = 'https://assset%d.cdn.com/test.png#sm';
var variants = 3;
var memoizedCdn = cdn(variants);
test('increments the count', () => {
const src = 'https://assset%d.cdn.com/test.png'
var variants = 5;
expect(memoizedCdn(asset1)).toBe('https://assset0.cdn.com/test.png');
expect(memoizedCdn(asset2)).toBe('https://assset1.cdn.com/test.jpg');
expect(memoizedCdn(asset3)).toBe('https://assset2.cdn.com/test.jpg?size=sm');
expect(memoizedCdn(asset4)).toBe('https://assset0.cdn.com/test.png#sm');
});
expect(cdn(src, variants)).toBe('https://assset0.cdn.com/test.png');
expect(cdn(src, variants)).toBe('https://assset1.cdn.com/test.png');
expect(cdn(src, variants)).toBe('https://assset2.cdn.com/test.png');
expect(cdn(src, variants)).toBe('https://assset3.cdn.com/test.png');
expect(cdn(src, variants)).toBe('https://assset4.cdn.com/test.png');
expect(cdn(src, variants)).toBe('https://assset0.cdn.com/test.png');
expect(cdn(src, variants)).toBe('https://assset1.cdn.com/test.png');
test('returns same string for the same string', () => {
expect(memoizedCdn(asset1)).toBe('https://assset0.cdn.com/test.png');
expect(memoizedCdn(asset2)).toBe('https://assset1.cdn.com/test.jpg');
expect(memoizedCdn(asset3)).toBe('https://assset2.cdn.com/test.jpg?size=sm');
expect(memoizedCdn(asset4)).toBe('https://assset0.cdn.com/test.png#sm');
});
var counter = require('./counter');
module.exports = function(src, variants) {
module.exports = function(variants) {
var variants = (variants || 4);
var cache = {};
return src.replace(/%d/, counter(variants));
};
return function(src) {
if (src in cache) {
return cache[src];
} else {
var save = src.replace(/%d/, counter(variants));
cache[src] = save;
return save;
}
}
}

@@ -5,12 +5,4 @@ module.exports = (function() {

return function(variants) {
var response = count;
count++
if (count > variants - 1) {
count = 0;
}
return response;
return count++ % variants;
}
})()
{
"name": "@procore/cdn",
"version": "1.0.2",
"version": "2.0.0",
"description": "Resolve the procore CDN",

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

@@ -5,4 +5,4 @@ # Resolve Procore CDN

Browsers only allow 6 current requests to the same domain. In order to overcome this restriction procore has 5
subdomains for fastly. This helper function will alternate between the subdomains in a sequence of 0-4.
Browsers only allow 6 current requests to the same domain. In order to overcome this restriction procore has 4
subdomains for fastly. This helper function will alternate between the subdomains in a sequence of 0-3 by default. The results are memoized, the same string will result with the same value.

@@ -12,6 +12,16 @@ ## Usage

```javascript
import cdn from '@procore/cdn';
cdn(numberOfDomains: number) {
return cached(bgImg: string)
return string
}
```
## Example
```javascript
import _cdn from '@procore/cdn';
import testImg from './test.png';
import bgImg from './bg.jpg';
const cdn = _cdn(4)

@@ -18,0 +28,0 @@ const App = () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc